そうです、Doctrine がこれをどのように行うのかをもう少し掘り下げて、その方法を知っていると思います。したがって、他の誰かがこれを行う必要がある場合は、ここで私がやっている方法を示します(フィードバックをいただければ幸いです)
注釈を読み取るために使用しているサービスがあるため、config.yml には、注釈をannotation_reader
読み取るためのメソッドへのアクセスを提供するサービスを含めました。
各注釈はクラスに解決する必要があり、クラスは基本 Doctrine 注釈クラスを拡張する必要があるため、私の質問から Foo 注釈を行うには、次のようにします。
namespace MyBundleName
class Foo extends \Doctrine\Common\Annotations\Annotation {
}
次に、次のようにして注釈を読み取ることができます。
$class = get_class($object);
foreach(object_get_vars($object) as $fieldname => $val){
//$this->annotationReader is an instance of the annotation_reader service
$annotations = $this->annotationReader
->getPropertyAnnotations(
new \ReflectionProperty($class, $fieldName)
);
//$annotations will now contain an array of matched annotations, most likely just an instance of the annotation class created earlier
}
それが他の誰かに役立つことを願っています!