我正在使用 Oneup\AclBundle,上次更新后我无法再保存任何实体。
当我尝试将实体保存到数据库时:
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
...我收到此错误:
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Oneup\AclBundle\EventListener\DoctrineSubscriber::postPersist() must be an instance of Doctrine\Common\Persistence\Event\LifecycleEventArgs, instance of Doctrine\ORM\Event\LifecycleEventArgs given, called in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php on line 61 and defined in vendor/oneup/acl-bundle/Oneup/AclBundle/EventListener/DoctrineSubscriber.php line 18
我发现 Oneup/AclBundle 发生了这样的变化: https://github.com/danez/OneupAclBundle/commit/f3eacf040677019caad73d221a610c73cbd7dd25
基于此,我尝试更改文件vendor/oneup/acl-bundle/Oneup/AclBundle/EventListener/DoctrineSubscriber.php:
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
...
class DoctrineSubscriber implements EventSubscriber
{
...
public function postPersist(LifecycleEventArgs $args)
{
...
$entity = $args->getObject();
$object = new \ReflectionClass($entity);
...
}
}
...至:
use Doctrine\ORM\Event\LifecycleEventArgs;
...
class DoctrineSubscriber implements EventSubscriber
{
...
public function postPersist(LifecycleEventArgs $args)
{
...
$entity = method_exists($args, 'getObject')? $args->getObject(): $args->getEntity(); // the called method sometimes changes
$object = new \ReflectionClass($entity);
...
}
}
...就像这样它可以工作。
如何通过此更新让一切恢复正常? 我想我必须以某种方式让一个共同的 Doctrine EventClass 被解雇,而不是一个 ORM Doctrine EventClass。
更新后,该 bundle 的日志为:
- Updating oneup/acl-bundle dev-master (b3c6ddb => fc3fdbc) Checking out fc3fdbcf3547f0e0520ebb7f7f7e86e3a05779d4
最佳答案
由于继承太窄和定义的 Composer 依赖关系太宽,引发了上述错误。
郑重声明:该错误已在 oneup/acl-bundle#7 中报告。并通过提交 d07385b 进行修复。如果遇到此错误,请将 bundle 更新到新版本 v0.9.1和 doctrine/orm
到 2.4.2
,如 the bug report 中提到的.
关于symfony - Oneup/AclBundle的DoctrineSubscriber中的Doctrine依赖变化导致的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21784677/