123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
-
-
-
- namespace Doctrine\Bundle\DoctrineBundle;
-
- use Doctrine\Common\Util\ClassUtils;
- use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
- use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
- use Doctrine\Bundle\DoctrineBundle\Command\Proxy\RunSqlDoctrineCommand;
- use Symfony\Component\Console\Application;
- use Symfony\Component\DependencyInjection\Compiler\PassConfig;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\HttpKernel\Bundle\Bundle;
- use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\DoctrineValidationPass;
- use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
- use Symfony\Bridge\Doctrine\DependencyInjection\Security\UserProvider\EntityFactory;
-
-
- class DoctrineBundle extends Bundle
- {
- private $autoloader;
-
-
-
- public function build(ContainerBuilder $container)
- {
- parent::build($container);
-
- $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass('doctrine.connections', 'doctrine.dbal.%s_connection.event_manager', 'doctrine'), PassConfig::TYPE_BEFORE_OPTIMIZATION);
-
- if ($container->hasExtension('security')) {
- $container->getExtension('security')->addUserProviderFactory(new EntityFactory('entity', 'doctrine.orm.security.user.provider'));
- }
- $container->addCompilerPass(new DoctrineValidationPass('orm'));
- }
-
-
-
- public function boot()
- {
-
-
- if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
- $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
- $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
-
-
- $container =& $this->container;
-
- $this->autoloader = function($class) use ($namespace, $dir, &$container) {
- if (0 === strpos($class, $namespace)) {
- $fileName = str_replace('\\', '', substr($class, strlen($namespace) +1));
- $file = $dir.DIRECTORY_SEPARATOR.$fileName.'.php';
-
- if (!is_file($file) && $container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
- $originalClassName = ClassUtils::getRealClass($class);
-
- $registry = $container->get('doctrine');
-
-
-
- foreach ($registry->getManagers() as $em) {
-
- if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
- $classes = $em->getMetadataFactory()->getAllMetadata();
-
- foreach ($classes as $classMetadata) {
- if ($classMetadata->name == $originalClassName) {
- $em->getProxyFactory()->generateProxyClasses(array($classMetadata));
- }
- }
- }
- }
-
- clearstatcache(true, $file);
- }
-
- if (file_exists($file)) {
- require $file;
- }
- }
- };
- spl_autoload_register($this->autoloader);
- }
- }
-
-
-
- public function shutdown()
- {
- if (null !== $this->autoloader) {
- spl_autoload_unregister($this->autoloader);
- $this->autoloader = null;
- }
- }
-
-
-
- public function registerCommands(Application $application)
- {
-
-
- if (class_exists('Doctrine\\ORM\\Version')) {
- parent::registerCommands($application);
-
- return;
- }
-
-
- $application->add(new CreateDatabaseDoctrineCommand());
- $application->add(new DropDatabaseDoctrineCommand());
- $application->add(new RunSqlDoctrineCommand());
- }
- }
|