1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
namespace Xervice\Database\Business\Model\Provider; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
use Propel\Runtime\Connection\ConnectionManagerInterface; |
9
|
|
|
use Propel\Runtime\ServiceContainer\ServiceContainerInterface; |
10
|
|
|
|
11
|
|
|
class PropelProvider implements PropelProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private $config; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Propel\Runtime\ServiceContainer\ServiceContainerInterface |
20
|
|
|
*/ |
21
|
|
|
private $serviceContainer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \Propel\Runtime\Connection\ConnectionManagerInterface |
25
|
|
|
*/ |
26
|
|
|
private $manager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* PropelProvider constructor. |
30
|
|
|
* |
31
|
|
|
* @param array $config |
32
|
|
|
* @param \Propel\Runtime\ServiceContainer\ServiceContainerInterface $serviceContainer |
33
|
|
|
* @param \Propel\Runtime\Connection\ConnectionManagerInterface $manager |
34
|
|
|
*/ |
35
|
1 |
|
public function __construct( |
36
|
|
|
array $config, |
37
|
|
|
ServiceContainerInterface $serviceContainer, |
38
|
|
|
ConnectionManagerInterface $manager |
39
|
|
|
) { |
40
|
1 |
|
$this->config = $config; |
41
|
1 |
|
$this->serviceContainer = $serviceContainer; |
42
|
1 |
|
$this->manager = $manager; |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function init(): void |
46
|
|
|
{ |
47
|
1 |
|
$this->createManager(); |
48
|
1 |
|
$this->configure(); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
private function createManager(): void |
52
|
|
|
{ |
53
|
1 |
|
$this->manager->setConfiguration($this->getManagerConfig()); |
|
|
|
|
54
|
1 |
|
$this->manager->setName('default'); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
1 |
|
private function getManagerConfig() |
61
|
|
|
{ |
62
|
1 |
|
$config = $this->config['propel']['database']['connections']['default']; |
63
|
1 |
|
$config['model_paths'] = [ |
64
|
|
|
0 => 'src', |
65
|
|
|
1 => 'vendor' |
66
|
|
|
]; |
67
|
1 |
|
return $config; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
private function configure(): void |
71
|
|
|
{ |
72
|
1 |
|
$this->serviceContainer->checkVersion('2.0.0'); |
73
|
1 |
|
$this->serviceContainer->checkVersion('2.0.0-dev'); |
74
|
1 |
|
$this->serviceContainer->setAdapterClass('default', 'pgsql'); |
75
|
1 |
|
$this->serviceContainer->setConnectionManager('default', $this->manager); |
76
|
1 |
|
$this->serviceContainer->setDefaultDatasource('default'); |
77
|
1 |
|
} |
78
|
|
|
} |
79
|
|
|
|