Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 467 lines (407 sloc) 19.326 kb
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
1 <?php
2
b3eebee @blue-eyes normalized license messages in PHP files
blue-eyes authored
3 /*
f92d177 @beberlei Fix LICENSE
beberlei authored
4 * This file is part of the Doctrine Bundle
5 *
6 * The code was originally distributed inside the Symfony framework.
b3eebee @blue-eyes normalized license messages in PHP files
blue-eyes authored
7 *
d1d6721 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
8 * (c) Fabien Potencier <fabien@symfony.com>
f92d177 @beberlei Fix LICENSE
beberlei authored
9 * (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
b3eebee @blue-eyes normalized license messages in PHP files
blue-eyes authored
10 *
11 * For the full copyright and license information, please view the LICENSE
12 * file that was distributed with this source code.
13 */
14
281539f @beberlei Adjust namespace from Symfony\Bundle to Doctrine\Bundle
beberlei authored
15 namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
16
3643e53 @schmittjoh some refactorings/improvements
schmittjoh authored
17 use Symfony\Component\DependencyInjection\Alias;
30a874a @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
18 use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 use Symfony\Component\DependencyInjection\Definition;
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
21 use Symfony\Component\DependencyInjection\DefinitionDecorator;
30a874a @fabpot renamed Symfony\Components to Symfony\Component
fabpot authored
22 use Symfony\Component\DependencyInjection\Reference;
e74d9a1 @beberlei [Doctrine] Remove AbstractDoctrineBundle and move code into Doctrine Bri...
beberlei authored
23 use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
6443261 @fabpot moved common configuration classes to a new Config component
fabpot authored
24 use Symfony\Component\Config\FileLocator;
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
25
26 /**
27 * DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
28 *
794cd21 @kriswallsmith Removed all those spaces after @author that were bothering me so…
kriswallsmith authored
29 * @author Jonathan H. Wage <jonwage@gmail.com>
d1d6721 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
30 * @author Fabien Potencier <fabien@symfony.com>
4fd5b29 @beberlei Introduced meta-bundle DoctrineAbstractBundle to squash 400+ loc of code...
beberlei authored
31 * @author Benjamin Eberlei <kontakt@beberlei.de>
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
32 */
4fd5b29 @beberlei Introduced meta-bundle DoctrineAbstractBundle to squash 400+ loc of code...
beberlei authored
33 class DoctrineExtension extends AbstractDoctrineExtension
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
34 {
f3e0851 @stof Removed the mysql charset hack for 5.3.6+ as PDO has been fixed
stof authored
35 private $defaultConnection;
36 private $entityManagers;
37
f0300fc @Engerim added PHPDocs
Engerim authored
38 /**
39 * {@inheritDoc}
40 */
801fbcd @lsmith77 implicitly load all registered bundles, all loading is now handled by lo...
lsmith77 authored
41 public function load(array $configs, ContainerBuilder $container)
42 {
80b3920 @kbond [Config] added ability to set info message and example to node definitio...
kbond authored
43 $configuration = $this->getConfiguration($configs, $container);
3e1f5f7 @fabpot updated all core extensions to use the new shortcut method
fabpot authored
44 $config = $this->processConfiguration($configuration, $configs);
801fbcd @lsmith77 implicitly load all registered bundles, all loading is now handled by lo...
lsmith77 authored
45
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
46 if (!empty($config['dbal'])) {
47 $this->dbalLoad($config['dbal'], $container);
801fbcd @lsmith77 implicitly load all registered bundles, all loading is now handled by lo...
lsmith77 authored
48 }
49
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
50 if (!empty($config['orm'])) {
51 $this->ormLoad($config['orm'], $container);
801fbcd @lsmith77 implicitly load all registered bundles, all loading is now handled by lo...
lsmith77 authored
52 }
53 }
54
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
55 /**
56 * Loads the DBAL configuration.
57 *
58 * Usage example:
59 *
60 * <doctrine:dbal id="myconn" dbname="sfweb" user="root" />
61 *
651aa8b @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
62 * @param array $config An array of configuration settings
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
63 * @param ContainerBuilder $container A ContainerBuilder instance
64 */
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
65 protected function dbalLoad(array $config, ContainerBuilder $container)
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
66 {
87bba5f @fabpot added a FileLocator to DIC so that we can load resources like @BundleNam...
fabpot authored
67 $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
8933d02 @beberlei Refactored Doctrine Bundle dbalLoad() to make use of config merging.
beberlei authored
68 $loader->load('dbal.xml');
69
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
70 if (empty($config['default_connection'])) {
346cc25 @fabpot fixed PHP warnings
fabpot authored
71 $keys = array_keys($config['connections']);
72 $config['default_connection'] = reset($keys);
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
73 }
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
74 $this->defaultConnection = $config['default_connection'];
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
75
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
76 $container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection));
77 $container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false));
5d1d01f @fabpot [DoctrineBundle] removed doctrine.dbal.types parameter
fabpot authored
78
51e726f @fabpot [DoctrineBundle] re-introduced parameters in the DIC for better overrida...
fabpot authored
79 $container->setParameter('doctrine.dbal.connection_factory.types', $config['types']);
8933d02 @beberlei Refactored Doctrine Bundle dbalLoad() to make use of config merging.
beberlei authored
80
5467abd @fabpot [DoctrineBundle] added a doctrine.dbal.connections parameter that keeps ...
fabpot authored
81 $connections = array();
82 foreach (array_keys($config['connections']) as $name) {
83 $connections[$name] = sprintf('doctrine.dbal.%s_connection', $name);
84 }
51e726f @fabpot [DoctrineBundle] re-introduced parameters in the DIC for better overrida...
fabpot authored
85 $container->setParameter('doctrine.connections', $connections);
86 $container->setParameter('doctrine.default_connection', $this->defaultConnection);
5467abd @fabpot [DoctrineBundle] added a doctrine.dbal.connections parameter that keeps ...
fabpot authored
87
8933d02 @beberlei Refactored Doctrine Bundle dbalLoad() to make use of config merging.
beberlei authored
88 foreach ($config['connections'] as $name => $connection) {
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
89 $this->loadDbalConnection($name, $connection, $container);
8933d02 @beberlei Refactored Doctrine Bundle dbalLoad() to make use of config merging.
beberlei authored
90 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
91 }
92
93 /**
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
94 * Loads a configured DBAL connection.
95 *
651aa8b @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
96 * @param string $name The name of the connection
97 * @param array $connection A dbal connection configuration.
98 * @param ContainerBuilder $container A ContainerBuilder instance
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
99 */
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
100 protected function loadDbalConnection($name, array $connection, ContainerBuilder $container)
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
101 {
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
102 // configuration
103 $configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new DefinitionDecorator('doctrine.dbal.connection.configuration'));
273bcdf @stof [DoctrineBridge][DoctrineBundle] Refactored the DBAL logging
stof authored
104 $logger = null;
105 if ($connection['logging']) {
106 $logger = new Reference('doctrine.dbal.logger');
107 }
108 unset ($connection['logging']);
109 if ($connection['profiling']) {
2d25592 @stof Updated the DI definitions for the data collector
stof authored
110 $profilingLoggerId = 'doctrine.dbal.logger.profiling.'.$name;
111 $container->setDefinition($profilingLoggerId, new DefinitionDecorator('doctrine.dbal.logger.profiling'));
112 $logger = new Reference($profilingLoggerId);
113 $container->getDefinition('data_collector.doctrine')->addMethodCall('addLogger', array($name, $logger));
114
115 if (null !== $logger) {
116 $chainLogger = new DefinitionDecorator('doctrine.dbal.logger.chain');
117 $chainLogger->addMethodCall('addLogger', array($logger));
118
119 $loggerId = 'doctrine.dbal.logger.chain.'.$name;
120 $container->setDefinition($loggerId, $chainLogger);
121 $logger = new Reference($loggerId);
122 }
273bcdf @stof [DoctrineBridge][DoctrineBundle] Refactored the DBAL logging
stof authored
123 }
124 unset($connection['profiling']);
f3e0851 @stof Removed the mysql charset hack for 5.3.6+ as PDO has been fixed
stof authored
125
a3a67db @joec4i Added support for schema assets filter configuration
joec4i authored
126 if (isset($connection['schema_filter']) && $connection['schema_filter']) {
127 $configuration->addMethodCall('setFilterSchemaAssetsExpression', array($connection['schema_filter']));
128 }
f3e0851 @stof Removed the mysql charset hack for 5.3.6+ as PDO has been fixed
stof authored
129
a3a67db @joec4i Added support for schema assets filter configuration
joec4i authored
130 unset($connection['schema_filter']);
273bcdf @stof [DoctrineBridge][DoctrineBundle] Refactored the DBAL logging
stof authored
131
132 if ($logger) {
133 $configuration->addMethodCall('setSQLLogger', array($logger));
520548e @beberlei [DoctrineBundle] Changed and simplified dbalLoad() slightly. Made loggin...
beberlei authored
134 }
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
135
53ccbd0 @beberlei Refactor Doctrine Bundle to use Symfony DIC Enabled EventManager.
beberlei authored
136 // event manager
ccd8888 @fabpot [DoctrineBundle] made some services private
fabpot authored
137 $def = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new DefinitionDecorator('doctrine.dbal.connection.event_manager'));
53ccbd0 @beberlei Refactor Doctrine Bundle to use Symfony DIC Enabled EventManager.
beberlei authored
138
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
139 // connection
f3e0851 @stof Removed the mysql charset hack for 5.3.6+ as PDO has been fixed
stof authored
140 // PDO ignores the charset property before 5.3.6 so the init listener has to be used instead.
141 if (isset($connection['charset']) && version_compare(PHP_VERSION, '5.3.6', '<')) {
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
142 if ((isset($connection['driver']) && stripos($connection['driver'], 'mysql') !== false) ||
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
143 (isset($connection['driver_class']) && stripos($connection['driver_class'], 'mysql') !== false)) {
60492f1 @beberlei Add support for MySQL Session Init Listener, refactored driver and drive...
beberlei authored
144 $mysqlSessionInit = new Definition('%doctrine.dbal.events.mysql_session_init.class%');
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
145 $mysqlSessionInit->setArguments(array($connection['charset']));
3643e53 @schmittjoh some refactorings/improvements
schmittjoh authored
146 $mysqlSessionInit->setPublic(false);
9836929 @fabpot [DoctrineBundle] refactored event listeners/subscribers to not rely on p...
fabpot authored
147 $mysqlSessionInit->addTag('doctrine.event_subscriber', array('connection' => $name));
60492f1 @beberlei Add support for MySQL Session Init Listener, refactored driver and drive...
beberlei authored
148
149 $container->setDefinition(
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
150 sprintf('doctrine.dbal.%s_connection.events.mysqlsessioninit', $name),
60492f1 @beberlei Add support for MySQL Session Init Listener, refactored driver and drive...
beberlei authored
151 $mysqlSessionInit
152 );
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
153 unset($connection['charset']);
60492f1 @beberlei Add support for MySQL Session Init Listener, refactored driver and drive...
beberlei authored
154 }
155 }
156
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
157 $options = $this->getConnectionOptions($connection);
6bf120f @beberlei Allow to override platform with your own by defining a service name.
beberlei authored
158
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
159 $container
160 ->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new DefinitionDecorator('doctrine.dbal.connection'))
161 ->setArguments(array(
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
162 $options,
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
163 new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
164 new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)),
1780ba4 @stof [DoctrineBundle] Added the support of custom types for the platform
stof authored
165 $connection['mapping_types'],
244e52c @fabpot [DoctrineBundle] converted DBAL definition templates to abstract definit...
fabpot authored
166 ))
167 ;
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
168 }
169
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
170 protected function getConnectionOptions($connection)
171 {
172 $options = $connection;
173
174 if (isset($options['platform_service'])) {
175 $options['platform'] = new Reference($options['platform_service']);
176 unset($options['platform_service']);
177 }
1780ba4 @stof [DoctrineBundle] Added the support of custom types for the platform
stof authored
178 unset($options['mapping_types']);
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
179
180 foreach (array(
beb5a52 @jonathaningram Implement "keep_slave"/"keepSlave" configuration
jonathaningram authored
181 'options' => 'driverOptions',
182 'driver_class' => 'driverClass',
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
183 'wrapper_class' => 'wrapperClass',
beb5a52 @jonathaningram Implement "keep_slave"/"keepSlave" configuration
jonathaningram authored
184 'keep_slave' => 'keepSlave',
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
185 ) as $old => $new) {
186 if (isset($options[$old])) {
187 $options[$new] = $options[$old];
188 unset($options[$old]);
189 }
190 }
191
0155938 @stof Added support for master_slave connections
stof authored
192 if (!empty($options['slaves'])) {
193 $nonRewrittenKeys = array(
beb5a52 @jonathaningram Implement "keep_slave"/"keepSlave" configuration
jonathaningram authored
194 'driver' => true, 'driverOptions' => true, 'driverClass' => true,
195 'wrapperClass' => true, 'keepSlave' => true,
0155938 @stof Added support for master_slave connections
stof authored
196 'platform' => true, 'slaves' => true, 'master' => true,
197 // included by safety but should have been unset already
198 'logging' => true, 'profiling' => true, 'mapping_types' => true, 'platform_service' => true,
199 );
200 foreach ($options as $key => $value) {
201 if (isset($nonRewrittenKeys[$key])) {
202 continue;
203 }
204 $options['master'][$key] = $value;
205 unset($options[$key]);
206 }
207 if (empty($options['wrapperClass'])) {
208 // Change the wrapper class only if the user does not already forced using a custom one.
209 $options['wrapperClass'] = 'Doctrine\\DBAL\\Connections\\MasterSlaveConnection';
210 }
211 } else {
212 unset($options['slaves']);
213 }
214
04d1fcc @fabpot [DoctrineBundle] fixed some configuration options
fabpot authored
215 return $options;
216 }
217
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
218 /**
8933d02 @beberlei Refactored Doctrine Bundle dbalLoad() to make use of config merging.
beberlei authored
219 * Loads the Doctrine ORM configuration.
220 *
221 * Usage example:
222 *
223 * <doctrine:orm id="mydm" connection="myconn" />
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
224 *
651aa8b @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
225 * @param array $config An array of configuration settings
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
226 * @param ContainerBuilder $container A ContainerBuilder instance
227 */
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
228 protected function ormLoad(array $config, ContainerBuilder $container)
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
229 {
87bba5f @fabpot added a FileLocator to DIC so that we can load resources like @BundleNam...
fabpot authored
230 $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38cb156 @beberlei [DoctrineBundle] Use a Merge Config algorithm for the ORM bundle. Simpli...
beberlei authored
231 $loader->load('orm.xml');
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
232
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
233 $this->entityManagers = array();
6a63998 @fabpot [DoctrineBundle] changed doctrine.orm.entity_managers parameter to store...
fabpot authored
234 foreach (array_keys($config['entity_managers']) as $name) {
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
235 $this->entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
6a63998 @fabpot [DoctrineBundle] changed doctrine.orm.entity_managers parameter to store...
fabpot authored
236 }
51e726f @fabpot [DoctrineBundle] re-introduced parameters in the DIC for better overrida...
fabpot authored
237 $container->setParameter('doctrine.entity_managers', $this->entityManagers);
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
238
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
239 if (empty($config['default_entity_manager'])) {
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
240 $tmp = array_keys($this->entityManagers);
6a63998 @fabpot [DoctrineBundle] changed doctrine.orm.entity_managers parameter to store...
fabpot authored
241 $config['default_entity_manager'] = reset($tmp);
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
242 }
51e726f @fabpot [DoctrineBundle] re-introduced parameters in the DIC for better overrida...
fabpot authored
243 $container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);
0caa285 @stof [DoctrineBundle] Use the first entity manager as default one when no con...
stof authored
244
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
245 $options = array('auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace');
38cb156 @beberlei [DoctrineBundle] Use a Merge Config algorithm for the ORM bundle. Simpli...
beberlei authored
246 foreach ($options as $key) {
247 $container->setParameter('doctrine.orm.'.$key, $config[$key]);
0d5f544 [DoctrineBundle] updated to only load default settings once
Brandon Turner authored
248 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
249
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
250 $container->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $config['default_entity_manager']));
4c98234 @fabpot changed all XML attribute names to take - instead of _ (everything shoul...
fabpot authored
251
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
252 foreach ($config['entity_managers'] as $name => $entityManager) {
253 $entityManager['name'] = $name;
254 $this->loadOrmEntityManager($entityManager, $container);
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
255 }
0db34cf @beberlei Add support for targetEntity resolving through the ORM 2.2 listener. Thi...
beberlei authored
256
257 if ($config['resolve_target_entities']) {
258 $def = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity');
259 foreach ($config['resolve_target_entities'] as $name => $implementation) {
260 $def->addMethodCall('addResolveTargetEntity', array(
261 $name, $implementation, array()
262 ));
263 }
264
265 $def->addTag('doctrine.event_listener', array('event' => 'loadClassMetadata'));
266 }
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
267 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
268
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
269 /**
270 * Loads a configured ORM entity manager.
271 *
f3e0851 @stof Removed the mysql charset hack for 5.3.6+ as PDO has been fixed
stof authored
272 * @param array $entityManager A configured ORM entity manager.
273 * @param ContainerBuilder $container A ContainerBuilder instance
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
274 */
275 protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container)
276 {
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
277 if ($entityManager['auto_mapping'] && count($this->entityManagers) > 1) {
dfe6bfd @fabpot [DoctrineBundle] removed the possibility to use auto_mapping when you ha...
fabpot authored
278 throw new \LogicException('You cannot enable "auto_mapping" when several entity managers are defined.');
279 }
280
8c5a912 @fabpot [DoctrineBundle] moved some more definition to abstract definition
fabpot authored
281 $ormConfigDef = $container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), new DefinitionDecorator('doctrine.orm.configuration'));
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
282
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
283 $this->loadOrmEntityManagerMappingInformation($entityManager, $ormConfigDef, $container);
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
284 $this->loadOrmCacheDrivers($entityManager, $container);
285
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
286 $methods = array(
287 'setMetadataCacheImpl' => new Reference(sprintf('doctrine.orm.%s_metadata_cache', $entityManager['name'])),
288 'setQueryCacheImpl' => new Reference(sprintf('doctrine.orm.%s_query_cache', $entityManager['name'])),
289 'setResultCacheImpl' => new Reference(sprintf('doctrine.orm.%s_result_cache', $entityManager['name'])),
290 'setMetadataDriverImpl' => new Reference('doctrine.orm.'.$entityManager['name'].'_metadata_driver'),
291 'setProxyDir' => '%doctrine.orm.proxy_dir%',
292 'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
293 'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
294 'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
bfa5759 @stof Added a way to configure the default entity repository class
stof authored
295 'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
296 );
e31a635 @naahuc add version_check to keep BC for naming_strategy
naahuc authored
297 // check for version to keep BC
298 if (version_compare(\Doctrine\ORM\Version::VERSION, "2.3.0-DEV") >= 0) {
299 $methods = array_merge($methods, array(
300 'setNamingStrategy' => new Reference($entityManager['naming_strategy']),
301 ));
302 }
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
303 foreach ($methods as $method => $arg) {
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
304 $ormConfigDef->addMethodCall($method, array($arg));
305 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
306
b43930e @francisbesset Moved hydrators configuration in entity manager
francisbesset authored
307 foreach ($entityManager['hydrators'] as $name => $class) {
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
308 $ormConfigDef->addMethodCall('addCustomHydrationMode', array($name, $class));
8534fdb @francisbesset [DoctrineBundle] Added custom hydrator for the EntityManager from config...
francisbesset authored
309 }
310
fe287f2 @stof [DoctrineBundle] Added a way to register custom DQL functions through th...
stof authored
311 if (!empty($entityManager['dql'])) {
312 foreach ($entityManager['dql']['string_functions'] as $name => $function) {
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
313 $ormConfigDef->addMethodCall('addCustomStringFunction', array($name, $function));
fe287f2 @stof [DoctrineBundle] Added a way to register custom DQL functions through th...
stof authored
314 }
315 foreach ($entityManager['dql']['numeric_functions'] as $name => $function) {
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
316 $ormConfigDef->addMethodCall('addCustomNumericFunction', array($name, $function));
fe287f2 @stof [DoctrineBundle] Added a way to register custom DQL functions through th...
stof authored
317 }
318 foreach ($entityManager['dql']['datetime_functions'] as $name => $function) {
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
319 $ormConfigDef->addMethodCall('addCustomDatetimeFunction', array($name, $function));
fe287f2 @stof [DoctrineBundle] Added a way to register custom DQL functions through th...
stof authored
320 }
321 }
322
94e2c5c @stof Added the support for SQL filters
stof authored
323 $enabledFilters = array();
324 foreach ($entityManager['filters'] as $name => $filter) {
325 $ormConfigDef->addMethodCall('addFilter', array($name, $filter['class']));
326 if ($filter['enabled']) {
327 $enabledFilters[] = $name;
328 }
329 }
330
331 $managerConfiguratorName = sprintf('doctrine.orm.%s_manager_configurator', $entityManager['name']);
332 $managerConfiguratorDef = $container
333 ->setDefinition($managerConfiguratorName, new DefinitionDecorator('doctrine.orm.manager_configurator.abstract'))
334 ->replaceArgument(0, $enabledFilters)
335 ;
336
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
337 if (!isset($entityManager['connection'])) {
338 $entityManager['connection'] = $this->defaultConnection;
339 }
d3f5fdf @fabpot [DoctrineBundle] introduced a Registry class
fabpot authored
340
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
341 $container
342 ->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new DefinitionDecorator('doctrine.orm.entity_manager.abstract'))
343 ->setArguments(array(
344 new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
345 new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name']))
346 ))
94e2c5c @stof Added the support for SQL filters
stof authored
347 ->setConfigurator(array(new Reference($managerConfiguratorName), 'configure'))
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
348 ;
38cb156 @beberlei [DoctrineBundle] Use a Merge Config algorithm for the ORM bundle. Simpli...
beberlei authored
349
350 $container->setAlias(
351 sprintf('doctrine.orm.%s_entity_manager.event_manager', $entityManager['name']),
f1439c9 @fabpot [DoctrineBundle] moved more DIC definition into orm.xml
fabpot authored
352 new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection']), false)
38cb156 @beberlei [DoctrineBundle] Use a Merge Config algorithm for the ORM bundle. Simpli...
beberlei authored
353 );
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
354 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
355
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
356 /**
357 * Loads an ORM entity managers bundle mapping information.
358 *
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
359 * There are two distinct configuration possibilities for mapping information:
360 *
d4782a1 @pborreli [DoctrineBundle] Fixed typo
pborreli authored
361 * 1. Specify a bundle and optionally details where the entity and mapping information reside.
362 * 2. Specify an arbitrary mapping location.
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
363 *
364 * @example
365 *
366 * doctrine.orm:
367 * mappings:
368 * MyBundle1: ~
369 * MyBundle2: yml
370 * MyBundle3: { type: annotation, dir: Entities/ }
371 * MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
372 * MyBundle5:
373 * type: yml
374 * dir: [bundle-mappings1/, bundle-mappings2/]
375 * alias: BundleAlias
376 * arbitrary_key:
377 * type: xml
378 * dir: %kernel.dir%/../src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Entities
379 * prefix: DoctrineExtensions\Entities\
380 * alias: DExt
381 *
382 * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but
383 * in the mappings key everything except alias is a required argument.
384 *
5989753 @fabpot [DoctrineBridge] fixed some CS
fabpot authored
385 * @param array $entityManager A configured ORM entity manager
386 * @param Definition $ormConfigDef A Definition instance
387 * @param ContainerBuilder $container A ContainerBuilder instance
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
388 */
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
389 protected function loadOrmEntityManagerMappingInformation(array $entityManager, Definition $ormConfigDef, ContainerBuilder $container)
390 {
391 // reset state of drivers and alias map. They are only used by this methods and children.
392 $this->drivers = array();
393 $this->aliasMap = array();
394
395 $this->loadMappingInformation($entityManager, $container);
396 $this->registerMappingDrivers($entityManager, $container);
441a000 @stof Completed the Configuration class and refactored the extension to use it
stof authored
397
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
398 $ormConfigDef->addMethodCall('setEntityNamespaces', array($this->aliasMap));
399 }
400
f0300fc @Engerim added PHPDocs
Engerim authored
401 /**
402 * {@inheritDoc}
403 */
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
404 protected function getObjectManagerElementName($name)
405 {
ebc0ade @fabpot [DoctrineBundle] fixed CS
fabpot authored
406 return 'doctrine.orm.'.$name;
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
407 }
408
409 protected function getMappingObjectDefaultName()
410 {
411 return 'Entity';
412 }
413
f0300fc @Engerim added PHPDocs
Engerim authored
414 /**
415 * {@inheritDoc}
416 */
ce98095 @beberlei refactored Doctrine*Bundle to allow a much more flexible configuration
beberlei authored
417 protected function getMappingResourceConfigDirectory()
418 {
936d4be @fabpot [DoctrineBundle] changed mapping directory
fabpot authored
419 return 'Resources/config/doctrine';
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
420 }
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
421
f0300fc @Engerim added PHPDocs
Engerim authored
422 /**
423 * {@inheritDoc}
424 */
98915de @stof [DoctrineBundle] Removed orm reference in DoctrineAbstractBundle
stof authored
425 protected function getMappingResourceExtension()
426 {
427 return 'orm';
428 }
429
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
430 /**
431 * Loads a configured entity managers cache drivers.
432 *
651aa8b @pborreli [Phpdoc] Cleaning/fixing
pborreli authored
433 * @param array $entityManager A configured ORM entity manager.
434 * @param ContainerBuilder $container A ContainerBuilder instance
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
435 */
436 protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container)
437 {
0cc5bb7 @bamarni using the abstract extension
bamarni authored
438 $this->loadObjectManagerCacheDriver($entityManager, $container, 'metadata_cache');
439 $this->loadObjectManagerCacheDriver($entityManager, $container, 'result_cache');
440 $this->loadObjectManagerCacheDriver($entityManager, $container, 'query_cache');
a219a69 @jwage [DoctrineBundle] Refactoring DoctrineBundle to match DoctrineMongoDBBund...
jwage authored
441 }
442
443 /**
f0300fc @Engerim added PHPDocs
Engerim authored
444 * {@inheritDoc}
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
445 */
446 public function getXsdValidationBasePath()
447 {
448 return __DIR__.'/../Resources/config/schema';
449 }
450
451 /**
f0300fc @Engerim added PHPDocs
Engerim authored
452 * {@inheritDoc}
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
453 */
454 public function getNamespace()
455 {
d1d6721 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
456 return 'http://symfony.com/schema/dic/doctrine';
d6cf350 @fabpot renamed Symfony\Framework to Symfony\Bundle
fabpot authored
457 }
80b3920 @kbond [Config] added ability to set info message and example to node definitio...
kbond authored
458
f0300fc @Engerim added PHPDocs
Engerim authored
459 /**
460 * {@inheritDoc}
461 */
80b3920 @kbond [Config] added ability to set info message and example to node definitio...
kbond authored
462 public function getConfiguration(array $config, ContainerBuilder $container)
463 {
464 return new Configuration($container->getParameter('kernel.debug'));
465 }
1c90ad0 @ornicar [DoctrineBundle] BC break - Load metadata files in Resources/config/doct...
ornicar authored
466 }
Something went wrong with that request. Please try again.