在Symfony 3.4 BETA 4中缺少元数据驱动程序

时间:2017-11-13 15:47:28

标签: symfony doctrine-orm

将我的项目从Symfony 3.4.0 BETA 2升级到3.4.0 BETA 4后,我在每个请求和每个cli命令中都出现以下错误:

[Doctrine\ORM\ORMException]
It's a requirement to specify a Metadata Driver and pass it to Doctrine\ORM\Configuration::setMetadataDriverImpl().

Exception trace:
Doctrine\ORM\ORMException::missingMappingDriverImpl() at D:\jinya-gallery-cms\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php:830
Doctrine\ORM\EntityManager::create() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:952
Container3xxrjsx\appDevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:2164
Container3xxrjsx\appDevDebugProjectContainer->getJinyaGallery_Monolog_MySqlHandlerService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:2299
Container3xxrjsx\appDevDebugProjectContainer->getMonolog_Logger_CacheService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:1508
Container3xxrjsx\appDevDebugProjectContainer->getCache_AnnotationsService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:1409
Container3xxrjsx\appDevDebugProjectContainer->getAnnotationReaderService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:940
Container3xxrjsx\appDevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:2164
Container3xxrjsx\appDevDebugProjectContainer->getJinyaGallery_Monolog_MySqlHandlerService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:2330
Container3xxrjsx\appDevDebugProjectContainer->getMonolog_Logger_EventService() at D:\jinya-gallery-cms\var\cache\dev\Container3xxrjsx\appDevDebugProjectContainer.php:1703
Container3xxrjsx\appDevDebugProjectContainer->getDebug_EventDispatcherService() at D:\jinya-gallery-cms\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:299
Symfony\Component\DependencyInjection\Container->get() at D:\jinya-gallery-cms\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:65
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at D:\jinya-gallery-cms\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:129
Symfony\Component\Console\Application->run() at D:\jinya-gallery-cms\bin\console:27

检查我发现的生成的缓存代码后,实例化EntityManager的代码与BETA 2中的代码完全不同。

这是来自BETA 2的代码:

<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
// Returns the public 'doctrine.orm.default_entity_manager' shared service.

$a = ${($_ = isset($this->services['annotation_reader']) ? $this->services['annotation_reader'] : $this->load(__DIR__.'/getAnnotationReaderService.php')) && false ?: '_'};

$b = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($a, array(0 => 'D:\\jinya-gallery-cms\\src\\HelperBundle\\Entity', 1 => 'D:\\jinya-gallery-cms\\src\\DataBundle\\Entity'));

$c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
$c->addDriver($b, 'HelperBundle\\Entity');
$c->addDriver($b, 'DataBundle\\Entity');
$c->addDriver(new \Doctrine\ORM\Mapping\Driver\XmlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array('D:\\jinya-gallery-cms\\vendor\\friendsofsymfony\\user-bundle\\Resources\\config\\doctrine-mapping' => 'FOS\\UserBundle\\Model'), '.orm.xml')), 'FOS\\UserBundle\\Model');

$d = new \Doctrine\ORM\Configuration();
$d->setEntityNamespaces(array('HelperBundle' => 'HelperBundle\\Entity', 'DataBundle' => 'DataBundle\\Entity'));
$d->setMetadataCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService.php')) && false ?: '_'});
$d->setQueryCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_query_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_query_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService.php')) && false ?: '_'});
$d->setResultCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_result_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_result_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService.php')) && false ?: '_'});
$d->setMetadataDriverImpl($c);
$d->setProxyDir(($this->targetDirs[0].'/doctrine/orm/Proxies'));
$d->setProxyNamespace('Proxies');
$d->setAutoGenerateProxyClasses(true);
$d->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
$d->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
$d->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
$d->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
$d->setEntityListenerResolver(${($_ = isset($this->services['doctrine.orm.default_entity_listener_resolver']) ? $this->services['doctrine.orm.default_entity_listener_resolver'] : $this->load(__DIR__.'/getDoctrine_Orm_DefaultEntityListenerResolverService.php')) && false ?: '_'});

$this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create(${($_ = isset($this->services['doctrine.dbal.default_connection']) ? $this->services['doctrine.dbal.default_connection'] : $this->load(__DIR__.'/getDoctrine_Dbal_DefaultConnectionService.php')) && false ?: '_'}, $d);

${($_ = isset($this->services['doctrine.orm.default_manager_configurator']) ? $this->services['doctrine.orm.default_manager_configurator'] : $this->services['doctrine.orm.default_manager_configurator'] = new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator(array(), array())) && false ?: '_'}->configure($instance);

return $instance;

这是来自BETA 4的代码

<?php

namespace ContainerXo2t2t9;

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
 * This class has been auto-generated
 * by the Symfony Dependency Injection Component.
 *
 * @final since Symfony 3.3
 */
class appDevDebugProjectContainer extends Container
{
/**
     * Gets the public 'doctrine.orm.default_entity_manager' shared service.
     *
     * @return \Doctrine\ORM\EntityManager
     */
    protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
    {
        $a = ${($_ = isset($this->services['doctrine.dbal.default_connection']) ? $this->services['doctrine.dbal.default_connection'] : $this->getDoctrine_Dbal_DefaultConnectionService()) && false ?: '_'};
        $b = ${($_ = isset($this->services['annotation_reader']) ? $this->services['annotation_reader'] : $this->getAnnotationReaderService()) && false ?: '_'};

        if (isset($this->services['doctrine.orm.default_entity_manager'])) {
            return $this->services['doctrine.orm.default_entity_manager'];
        }

        $c = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($b, array(0 => 'D:\\jinya-gallery-cms\\src\\HelperBundle\\Entity', 1 => 'D:\\jinya-gallery-cms\\src\\DataBundle\\Entity'));

        $d = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();

        $e = new \Doctrine\ORM\Configuration();

        $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($a, $e);

        $d->addDriver($c, 'HelperBundle\\Entity');
        $d->addDriver($c, 'DataBundle\\Entity');
        $d->addDriver(new \Doctrine\ORM\Mapping\Driver\XmlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array('D:\\jinya-gallery-cms\\vendor\\friendsofsymfony\\user-bundle\\Resources\\config\\doctrine-mapping' => 'FOS\\UserBundle\\Model'), '.orm.xml')), 'FOS\\UserBundle\\Model');
        $e->setEntityNamespaces(array('HelperBundle' => 'HelperBundle\\Entity', 'DataBundle' => 'DataBundle\\Entity'));
        $e->setMetadataCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService()) && false ?: '_'});
        $e->setQueryCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_query_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_query_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService()) && false ?: '_'});
        $e->setResultCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_result_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_result_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService()) && false ?: '_'});
        $e->setMetadataDriverImpl($d);
        $e->setProxyDir(($this->targetDirs[0].'/doctrine/orm/Proxies'));
        $e->setProxyNamespace('Proxies');
        $e->setAutoGenerateProxyClasses(true);
        $e->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        $e->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        $e->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
        $e->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
        $e->setEntityListenerResolver(${($_ = isset($this->services['doctrine.orm.default_entity_listener_resolver']) ? $this->services['doctrine.orm.default_entity_listener_resolver'] : $this->services['doctrine.orm.default_entity_listener_resolver'] = new \Doctrine\Bundle\DoctrineBundle\Mapping\ContainerAwareEntityListenerResolver($this)) && false ?: '_'});

        ${($_ = isset($this->services['doctrine.orm.default_manager_configurator']) ? $this->services['doctrine.orm.default_manager_configurator'] : $this->services['doctrine.orm.default_manager_configurator'] = new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator(array(), array())) && false ?: '_'}->configure($instance);

        return $instance;
    }
}

结果是,在BETA 4中,在设置配置值之前创建EntityManager。有谁知道如何影响缓存生成以创建工作缓存?

1 个答案:

答案 0 :(得分:1)

对我有用的解决方案:

  1. 使用composer require ocramius/proxy-manager
  2. 安装Lazy Services
  3. 对于每个侦听器,在lazy: true

    中设置其他参数tags
    app.service_doctrine.foo_listerner:
    class: AppBundle\Service\Doctrine\FooListener
    ...
    tags:
        - { name: doctrine.orm.entity_listener, entity_manager: default, lazy: true }