作为我不时发布的CMS开发的一部分,..我遇到了一个问题。
错误:
[语义错误] ScyLabs \ GiftCodeBundle \ Entity \ GiftCode类中的注释“ @Doctrine \ ORM \ Mapping \ Entity”不存在,或者无法自动加载。
我向您解释,
基本上,在项目中,所有内容都是可重写的,已经存在,并且在文件services.yaml中具有配置。
出于简单性的明显原因,并且迫切需要,让我创建第二个继承自它的包。我告诉自己,做我的“覆盖”或对项目说:“您好,我是一个班级在用我”,使用注释非常方便(而且更加清楚)。
所以,我创建了一个自定义批注(到目前为止非常好..),您在这里可以找到..
<?php
/**
* Created by PhpStorm.
* User: alex
* Date: 04/11/2019
* Time: 14:25
*/
namespace ScyLabs\NeptuneBundle\Annotation\ScyLabsNeptune;
/**
* @Annotation
* @Target({"CLASS"})
* @Attributes({
* @Attribute("key",type="string"),
* @Attribute("classNameSpace",type="string"),
* })
*/
class Override
{
/**
* @var string
*/
public $key;
/**
* @var string
*/
public $classNameSpace;
public function __construct(array $opts) {
$this->key = $opts['value'];
$this->classNameSpace = $opts['class'];
}
}
好,我的注释已经到位,我现在将其放在一个实体中,..如下所示
<?php
/**
* Created by PhpStorm.
* User: alex
* Date: 05/11/2019
* Time: 10:20
*/
namespace ScyLabs\GiftCodeBundle\Entity;
use ScyLabs\NeptuneBundle\Annotation\ScyLabsNeptune;
use Doctrine\ORM\Mapping as ORM;
/**
* @ScyLabsNeptune\Override("gift",class="ScyLabs\GiftCodeBundle\Entity\GiftCode")
* @ORM\Entity()
*/
class GiftCode
{
}
为什么这么做?实际上,在海王星中,一切都是自动化的,除了特殊情况,它将自动生成实体正常运行所必需的所有URL(ADD / EDIT / DELETE / LIST)...为此,它必须指示实体存在的项目,并且该实体必须是该系统的一部分。
所以,到目前为止,我在services.yaml中使用了非常完整的配置,在其中我填充了一个表键=>值,对应于“ key” =>“ Namespace”]
在我的情况下:“礼物” =>“ ScyLabs \ GiftCodeBundle \实体\ GiftCode”
总之,突然之间,为了覆盖,我在编译步骤中进行了处理
<?php
/**
* Created by PhpStorm.
* User: alex
* Date: 01/08/2018
* Time: 09:46
*/
namespace ScyLabs\NeptuneBundle;
class ScyLabsNeptuneBundle extends Bundle
{
public function getContainerExtension()
{
// Compilation de l'extension
return new ScyLabsNeptuneExtension();
}
}
在此扩展中,我有这段代码可以构成所有内容
$bundles = require $projectDir.'/config/bundles.php';
foreach ($bundles as $bundle => $env){
if($bundle === ScyLabsNeptuneBundle::class)
continue;
if(method_exists(new $bundle,'getParent') && (new $bundle)->getParent() === ScyLabsNeptuneBundle::class){
$reader = new AnnotationReader();
$reflClass = new \ReflectionClass(GiftCode::class);
$classAnotations = $reader->getClassAnnotation($reflClass,"Override");
foreach ($classAnotations as $classAnotation){
if($classAnotation instanceof Override && class_exists($classAnotation->classNameSpace)){
$config['override'][$classAnotation->key] = $classAnotation->classNameSpace; }
}
}
}
[经过大量研究后,我怀疑在扩展程序@ORM \ Entity和/或// Autowire的编译阶段,它似乎尚未编译。
问题是突然间,当我得到我的个人注释(覆盖)时,我无法恢复@ORM \ Entity,并且由于它不再作为实体起作用,因此我也不必删除它。
为什么在这里?因为在后面,我还有另一步整理(A CompilationPass)
$container->addCompilerPass(new ResolveDoctrineTargetEntitiesPass(),PassConfig::TYPE_BEFORE_OPTIMIZATION,1000);
谁重新定义了与我发送给他的画作有关的学说的实体(您知道,我刚刚定义的那个实体。
因此,我可以覆盖具有相同名称的实体。
做什么? ..我承认我不能做更多...
感谢预先的朋友;)
默认情况下,注释阅读器不使用与类相同的自动加载器。您需要告诉他如何像这样加载注释类: