Doctrine PHP DataFixture:“编译错误:无法重新声明类”

时间:2017-02-09 10:08:21

标签: php symfony doctrine-orm

我创建了一个PHP类来生成一些灯具:

namespace DashboardBundle\DataFixtures\ORM;

use DashboardBundle\Entity\Property;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadPropertyData extends AbstractFixture implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
{
    /** @var  ContainerInterface */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function load(ObjectManager $manager)
    {
        $properties = $this->container->get('dashboard.properties_generator');

        foreach ($properties as $key => $propertyConfig) {
            $property = new Property();
            $property->setName($key);
            $property->setType($propertyConfig);

            $this->addReference('property-' . $key, $property);

            $manager->persist($property);
        }

        $manager->flush();
    }

    public function getOrder()
    {
        return  1;
    }
}

但是我收到了这个错误:

➜  dashboard git:(guillaume) ✗ bin/console -v fixtures:load

/* ... some stuff ... */

[Symfony\Component\Debug\Exception\FatalErrorException]                                              
Compile Error: Cannot redeclare class DashboardBundle\DataFixtures\ORM\LoadPropertyData

似乎名称空间,类名似乎是正确的。 DashboardBundle \ DataFixtures \ ORM 目录中没有其他文件。

我试图重启服务器(PHP-FPM和Nginx),我试图清除Symfony缓存,但没有效果。

简而言之,我不知道为什么Symfony抛出此异常。 任何的想法 ?谢谢!

0 个答案:

没有答案