123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace Symfony\Framework\DoctrineBundle\DependencyInjection;
- use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
- use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
- use Symfony\Components\DependencyInjection\BuilderConfiguration;
- /*
- * This file is part of the symfony framework.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- /**
- * DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
- *
- * @package symfony
- * @subpackage dependency_injection
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
- class DoctrineExtension extends LoaderExtension
- {
- protected $resources = array(
- 'dbal' => 'dbal.xml',
- 'orm' => 'orm.xml',
- );
- protected $alias;
- public function setAlias($alias)
- {
- $this->alias = $alias;
- }
- /**
- * Loads the DBAL configuration.
- *
- * Usage example:
- *
- * <doctrine:dbal dbname="sfweb" user="root" />
- *
- * @param array $config A configuration array
- *
- * @return BuilderConfiguration A BuilderConfiguration instance
- */
- public function dbalLoad($config)
- {
- $configuration = new BuilderConfiguration();
- $loader = new XmlFileLoader(__DIR__.'/../Resources/config');
- $configuration->merge($loader->load($this->resources['dbal']));
- foreach (array('dbname', 'host', 'user', 'password', 'path', 'port') as $key)
- {
- if (isset($config[$key]))
- {
- $configuration->setParameter('doctrine.dbal.'.$key, $config[$key]);
- }
- }
- if (isset($config['options']))
- {
- $configuration->setParameter('doctrine.dbal.driver.options', $config['options']);
- }
- if (isset($config['driver']))
- {
- $class = $config['driver'];
- if (in_array($class, array('OCI8', 'PDOMsSql', 'PDOMySql', 'PDOOracle', 'PDOPgSql', 'PDOSqlite')))
- {
- $class = 'Doctrine\\DBAL\\Driver\\'.$class.'\\Driver';
- }
- $configuration->setParameter('doctrine.dbal.driver.class', $class);
- }
- $configuration->setAlias('database_connection', null !== $this->alias ? $this->alias : 'doctrine.dbal.connection');
- return $configuration;
- }
- /**
- * Loads the Doctrine ORM configuration.
- *
- * @param array $config A configuration array
- *
- * @return BuilderConfiguration A BuilderConfiguration instance
- */
- public function ormLoad($config)
- {
- $configuration = new BuilderConfiguration();
- $loader = new XmlFileLoader(__DIR__.'/../Resources/config');
- $configuration->merge($loader->load($this->resources['orm']));
- return $configuration;
- }
- /**
- * Returns the base path for the XSD files.
- *
- * @return string The XSD base path
- */
- public function getXsdValidationBasePath()
- {
- return __DIR__.'/../Resources/config/';
- }
- /**
- * Returns the namespace to be used for this extension (XML namespace).
- *
- * @return string The XML namespace
- */
- public function getNamespace()
- {
- return 'http://www.symfony-project.org/schema/dic/doctrine';
- }
- /**
- * Returns the recommanded alias to use in XML.
- *
- * This alias is also the mandatory prefix to use when using YAML.
- *
- * @return string The alias
- */
- public function getAlias()
- {
- return 'doctrine';
- }
- }
|