1 | <?php |
||
20 | class DBALConnectionFactory extends AbstractFactory |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritDoc} |
||
24 | * |
||
25 | * @return Connection |
||
26 | */ |
||
27 | 76 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
28 | { |
||
29 | /** @var $options DBALConnection */ |
||
30 | 76 | $options = $this->getOptions($container, 'connection'); |
|
31 | 76 | $pdo = $options->getPdo(); |
|
32 | |||
33 | 76 | if (is_string($pdo)) { |
|
34 | $pdo = $container->get($pdo); |
||
35 | } |
||
36 | |||
37 | $params = [ |
||
38 | 76 | 'driverClass' => $options->getDriverClass(), |
|
39 | 76 | 'wrapperClass' => $options->getWrapperClass(), |
|
40 | 76 | 'pdo' => $pdo, |
|
41 | ]; |
||
42 | 76 | $params = array_merge($params, $options->getParams()); |
|
43 | |||
44 | 76 | if (array_key_exists('platform', $params) |
|
45 | 76 | && is_string($params['platform']) |
|
46 | 76 | && $container->has($params['platform']) |
|
47 | ) { |
||
48 | 1 | $params['platform'] = $container->get($params['platform']); |
|
49 | } |
||
50 | |||
51 | 76 | $configuration = $container->get($options->getConfiguration()); |
|
52 | 76 | $eventManager = $container->get($options->getEventManager()); |
|
53 | |||
54 | 76 | $connection = DriverManager::getConnection($params, $configuration, $eventManager); |
|
55 | 76 | foreach ($options->getDoctrineTypeMappings() as $dbType => $doctrineType) { |
|
56 | 2 | $connection->getDatabasePlatform()->registerDoctrineTypeMapping($dbType, $doctrineType); |
|
57 | } |
||
58 | |||
59 | 76 | foreach ($options->getDoctrineCommentedTypes() as $type) { |
|
60 | 1 | $connection->getDatabasePlatform()->markDoctrineTypeCommented(Type::getType($type)); |
|
61 | } |
||
62 | |||
63 | 76 | return $connection; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | * @return Connection |
||
69 | */ |
||
70 | 76 | public function createService(ServiceLocatorInterface $container) |
|
74 | |||
75 | /** |
||
76 | * Get the class name of the options associated with this factory. |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | 76 | public function getOptionsClass() |
|
84 | } |
||
85 |