@@ -44,76 +44,76 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class DoctrineBootstrap { |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * entity manager |
|
| 49 | - * |
|
| 50 | - * @var _entityManager EnitytManager |
|
| 51 | - */ |
|
| 52 | - private static $_entityManager; |
|
| 47 | + /** |
|
| 48 | + * entity manager |
|
| 49 | + * |
|
| 50 | + * @var _entityManager EnitytManager |
|
| 51 | + */ |
|
| 52 | + private static $_entityManager; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * loading envs |
|
| 56 | - */ |
|
| 57 | - private static function _loadEnv() { |
|
| 58 | - if (getenv ( 'DB_NAME' ) != null && getenv ( 'DB_NAME' ) != "") { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 61 | - if (defined ( 'ABSPATH' )) { |
|
| 62 | - \Dotenv::load ( ABSPATH ); |
|
| 63 | - } else { |
|
| 64 | - \Dotenv::load ( getenv ( 'HOME' ) ); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - private static function getPaths() { |
|
| 68 | - if (file_exists ( getcwd () . "/src/Entities" )) { |
|
| 69 | - return array ( |
|
| 70 | - getcwd () . "/src/Entities" |
|
| 71 | - ); |
|
| 72 | - } else { |
|
| 73 | - return array ( |
|
| 74 | - getcwd () . "/vendor/amarcinkowski/hospitalplugin/src/Entities" |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - } |
|
| 54 | + /** |
|
| 55 | + * loading envs |
|
| 56 | + */ |
|
| 57 | + private static function _loadEnv() { |
|
| 58 | + if (getenv ( 'DB_NAME' ) != null && getenv ( 'DB_NAME' ) != "") { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | + if (defined ( 'ABSPATH' )) { |
|
| 62 | + \Dotenv::load ( ABSPATH ); |
|
| 63 | + } else { |
|
| 64 | + \Dotenv::load ( getenv ( 'HOME' ) ); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + private static function getPaths() { |
|
| 68 | + if (file_exists ( getcwd () . "/src/Entities" )) { |
|
| 69 | + return array ( |
|
| 70 | + getcwd () . "/src/Entities" |
|
| 71 | + ); |
|
| 72 | + } else { |
|
| 73 | + return array ( |
|
| 74 | + getcwd () . "/vendor/amarcinkowski/hospitalplugin/src/Entities" |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * |
|
| 81 | - * @return entityManager EntityManager |
|
| 82 | - */ |
|
| 83 | - private static function _getInstance() { |
|
| 84 | - $isDevMode = true; |
|
| 85 | - $config = Setup::createAnnotationMetadataConfiguration ( self::getPaths (), $isDevMode ); |
|
| 86 | - self::_loadEnv (); |
|
| 87 | - $conn = array ( |
|
| 88 | - 'dbname' => getenv ( 'DB_NAME' ), |
|
| 89 | - 'user' => getenv ( 'DB_USER' ), |
|
| 90 | - 'password' => getenv ( 'DB_PASSWORD' ), |
|
| 91 | - 'host' => getenv ( 'DB_HOST' ), |
|
| 92 | - 'driver' => 'pdo_mysql', |
|
| 93 | - 'charset' => 'utf8', |
|
| 94 | - 'driverOptions' => array ( |
|
| 95 | - 1002 => 'SET NAMES utf8' |
|
| 96 | - ), |
|
| 97 | - 'mapping_types' => 'enum:string' |
|
| 98 | - ); |
|
| 99 | - return EntityManager::create ( $conn, $config ); |
|
| 100 | - } |
|
| 79 | + /** |
|
| 80 | + * |
|
| 81 | + * @return entityManager EntityManager |
|
| 82 | + */ |
|
| 83 | + private static function _getInstance() { |
|
| 84 | + $isDevMode = true; |
|
| 85 | + $config = Setup::createAnnotationMetadataConfiguration ( self::getPaths (), $isDevMode ); |
|
| 86 | + self::_loadEnv (); |
|
| 87 | + $conn = array ( |
|
| 88 | + 'dbname' => getenv ( 'DB_NAME' ), |
|
| 89 | + 'user' => getenv ( 'DB_USER' ), |
|
| 90 | + 'password' => getenv ( 'DB_PASSWORD' ), |
|
| 91 | + 'host' => getenv ( 'DB_HOST' ), |
|
| 92 | + 'driver' => 'pdo_mysql', |
|
| 93 | + 'charset' => 'utf8', |
|
| 94 | + 'driverOptions' => array ( |
|
| 95 | + 1002 => 'SET NAMES utf8' |
|
| 96 | + ), |
|
| 97 | + 'mapping_types' => 'enum:string' |
|
| 98 | + ); |
|
| 99 | + return EntityManager::create ( $conn, $config ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * returns enitytManager |
|
| 104 | - * |
|
| 105 | - * @return EntityManager |
|
| 106 | - */ |
|
| 107 | - public static function getEntityManager() { |
|
| 108 | - if (self::$_entityManager == null) { |
|
| 109 | - self::$_entityManager = self::_getInstance (); |
|
| 110 | - } |
|
| 111 | - return self::$_entityManager; |
|
| 112 | - } |
|
| 113 | - public static function getCli() { |
|
| 114 | - $em = DoctrineBootstrap::getEntityManager (); |
|
| 115 | - $em->getConnection ()->getDatabasePlatform ()->registerDoctrineTypeMapping ( 'enum', 'string' ); |
|
| 116 | - return ConsoleRunner::createHelperSet ( $em ); |
|
| 117 | - } |
|
| 102 | + /** |
|
| 103 | + * returns enitytManager |
|
| 104 | + * |
|
| 105 | + * @return EntityManager |
|
| 106 | + */ |
|
| 107 | + public static function getEntityManager() { |
|
| 108 | + if (self::$_entityManager == null) { |
|
| 109 | + self::$_entityManager = self::_getInstance (); |
|
| 110 | + } |
|
| 111 | + return self::$_entityManager; |
|
| 112 | + } |
|
| 113 | + public static function getCli() { |
|
| 114 | + $em = DoctrineBootstrap::getEntityManager (); |
|
| 115 | + $em->getConnection ()->getDatabasePlatform ()->registerDoctrineTypeMapping ( 'enum', 'string' ); |
|
| 116 | + return ConsoleRunner::createHelperSet ( $em ); |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |