|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* DoctrineBootstrap |
|
5
|
|
|
* |
|
6
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
|
7
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted to use or copy this program |
|
10
|
|
|
* for any purpose, provided the above notices are retained on all copies. |
|
11
|
|
|
* Permission to modify the code and to distribute modified code is granted, |
|
12
|
|
|
* provided the above notices are retained, and a notice that the code was |
|
13
|
|
|
* modified is included with the above copyright notice. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Wp |
|
16
|
|
|
* @package Punction |
|
17
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
18
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
19
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
20
|
|
|
* @version 1.0 $Id$ $Format:%H$ |
|
21
|
|
|
* @link http:// |
|
22
|
|
|
* @since File available since Release 1.0.0 |
|
23
|
|
|
* PHP Version 5 |
|
24
|
|
|
*/ |
|
25
|
|
|
namespace Hospitalplugin\DB; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\ORM\Tools\Setup; |
|
28
|
|
|
use Doctrine\ORM\EntityManager; |
|
29
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner; |
|
30
|
|
|
// php vendor/bin/doctrine orm:schema-tool:update --force --dump-sql |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* DoctrineBootstrap |
|
34
|
|
|
* |
|
35
|
|
|
* @category Wp |
|
36
|
|
|
* @package Punction |
|
37
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
38
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
39
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
40
|
|
|
* @version 1.0 $Id$ $Format:%H$ |
|
41
|
|
|
* @link http:// |
|
42
|
|
|
* @since File available since Release 1.0.0 |
|
43
|
|
|
* |
|
44
|
|
|
*/ |
|
45
|
|
|
class DoctrineBootstrap { |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* entity manager |
|
49
|
|
|
* |
|
50
|
|
|
* @var _entityManager EnitytManager |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $_entityManager; |
|
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
|
|
|
} |
|
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
|
|
|
} |
|
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
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..