1

这是我最初的 MyEntity.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * MyEntity 
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AppBundle\Entity\MyEntityRepository")
 */
class MyEntity
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @var string
     *
     * @ORM\Column(name="string", type="string", length=255)
     */
    private $string;

}

我很惊讶,因为当你运行命令时:

php app/console doctrine:generate:entities AppBundle/Entity/MyEntity

在我的实体中,生成了以下带有$condition的代码,而事实是我无法弄清楚它们是如何以及为什么被创建的。

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * MyEntity 
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AppBundle\Entity\MyEntityRepository")
 */
class MyEntity
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @var string
     *
     * @ORM\Column(name="string", type="string", length=255)
     */
    private $string;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Set string
     *
     * @param string $string
     * @return MyEntity
     */
    public function setString($string) {
        $this->string = $string;

        return $this;
    }

    /**
     * Get string
     *
     * @return string 
     */
    public function getString() {
        return $this->string;
    }

    /**
     * @var string
     */
    private $condition;


    /**
     * Set condition
     *
     * @param string $condition
     * @return MyEntity
     */
    public function setCondition($condition)
    {
        $this->condition = $condition;

        return $this;
    }

    /**
     * Get condition
     *
     * @return string 
     */
    public function getCondition()
    {
        return $this->condition;
    }

}

这是我的 composer.json

{
"name": "project/symfony2.8",
"license": "proprietary",
"type": "project",
"autoload": {
    "psr-4": {
        "": "src/"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},
"require": {
    "php": ">=5.3.9",

    "symfony/symfony": "2.8.*",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "symfony/assetic-bundle": "^2.8",

    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "doctrine/doctrine-fixtures-bundle": "^2.3",

    "sensio/distribution-bundle": "~5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "sensio/generator-bundle": "~2.3",        

    "incenteev/composer-parameter-handler": "~2.0",

    "sonata-project/doctrine-orm-admin-bundle": "~2.3",
    "sonata-project/admin-bundle": "~2.3",
    "sonata-project/user-bundle": "^2.2",
    "sonata-project/intl-bundle": "^2.2",  
    "sonata-project/media-bundle": "^2.3",
    "sonata-project/formatter-bundle": "^2.3", 
    "sonata-project/seo-bundle": "~1",     

    "jms/serializer-bundle": "~0.13",   
    "jms/i18n-routing-bundle": "^2.0",        
    "jms/translation-bundle": "^1.2",
    "jms/di-extra-bundle": "^1.7",

    "knplabs/doctrine-behaviors": "^1.3",

    "a2lix/translation-form-bundle": "^2.1",

    "oh/google-map-form-type-bundle": "dev-master",  
    "egeloen/google-map-bundle": "^2.2",
    "willdurand/geocoder": "^3.3",
    "widop/http-adapter-bundle": "^1.2",

    "pixassociates/sortable-behavior-bundle": "^1.0",
    "stof/doctrine-extensions-bundle": "^1.2",

    "avegao/spain-validator-bundle": "^1.0",

    "xmon/color-picker-type-bundle": "^1.0",

    "urodoz/truncate-html": "@stable",

    "suncat/mobile-detect-bundle": "0.10.*",

    "symfony-cmf/seo-bundle": "^1.2",
    "burgov/key-value-form-bundle": "^1.4"


},
"require-dev": {
    "symfony/phpunit-bridge": "~2.7"
},
"scripts": {
    "post-install-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ],
    "post-update-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
    ]
},
"config": {
    "bin-dir": "bin",
    "platform": {
        "php": "5.4.45"
    }
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "symlink",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    }
}

}

有什么想法吗?多谢

4

1 回答 1

1

似乎有一个遗留的 MetadataListener,它是通用的,将映射添加到所有实体。

一个简短的解决方法是注释掉映射完成的行

/*
 * This file is part of the Symfony CMF package.
 *
 * (c) 2011-2015 Symfony CMF
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata as PhpcrClassMetadata;

/**
 * Metadata listener to remove mapping for condition field if the field does not exist.
 *
 * The condition option was only added in Symfony 2.4 and is missing from 2.3.
 * When we drop Symfony 2.3 support, this listener can be dropped.
 *
 * @author David Buchmann <mail@davidbu.ch>
 */
class RouteConditionMetadataListener implements EventSubscriber
{
    /**
     * @return array
     */
    public function getSubscribedEvents()
    {
        return array(
            'loadClassMetadata',
        );
    }

    /**
     * Handle the load class metadata event: remove translated attribute from
     * fields and remove the locale mapping if present.
     *
     * @param LoadClassMetadataEventArgs $eventArgs
     */
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        if (!property_exists('Symfony\Component\Routing\Route', 'condition')) {
            return; // nothing to do
        }

        $meta = $eventArgs->getClassMetadata();
        $refl = $meta->getReflectionClass();
        if (null !== $refl && 'Symfony\Component\Routing\Route' !== $refl->getName()) {
            return;
        }
//
//        if ($meta instanceof OrmClassMetadata) {
//            /* @var $meta OrmClassMetadata */
//            $meta->mapField(array(
//                'fieldName' => 'condition',
//                'columnName' => 'condition_expr',
//                'type' => 'string',
//                'nullable' => true,
//            ));
//        } elseif ($meta instanceof PhpcrClassMetadata) {
//            /* @var $meta PhpcrClassMetadata */
//            $meta->mapField(array(
//                'fieldName' => 'condition',
//                'type' => 'string',
//                'nullable' => true,
//            ));
//        } else {
//            throw new \LogicException(sprintf('Class metadata was neither PHPCR nor ORM but %s', get_class($meta)));
//        }
    }
}

并运行命令

php app/console doctrine:generate:entities AppBundle/Entity/MyEntity

于 2016-07-20T08:52:23.490 回答