Doctrineのカスタムアノテーションに関するこのドキュメント記事を読んでいます。$reader->getClassAnnotations($reflClass)
特定のクラスのアノテーションを取得するために使用できることを理解しています。特定のアノテーションを持つすべてのエンティティクラスのリストを取得するための最良の方法は何ですか?
2219 次
1 に答える
2
$driver = new \Doctrine\ORM\Mapping\Driver\PHPDriver($entities_path );
$classes = $driver->getAllClassNames();
foreach ($classes as $key => $class) {
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$annotationReader = new \Doctrine\Common\Annotations\CachedReader(
$reader,
new \Doctrine\Common\Cache\ArrayCache()
);
$reflClass = new ReflectionClass("\Entities\\".$reportableClass);
$annotation = $annotationReader->getClassAnnotation(
$reflClass,
'Custom_Annotation'
);
if (is_null($annotation)) {
unset($classes[$key]);
}
}
DoctrineのAbstractFileDriver(Doctrine \ ORM \ Mapping \ Driver \ AbstractFileDriver.php)ドキュメントは次のように述べています。
ファイルベースのメタデータドライバーのベースドライバー。
ファイルドライバは、個々のクラスのマッピングファイルをオンデマンドでロードするモードで動作します。これには、ユーザーがクラスごとに1つのマッピングファイルの規則に従う必要があり、マッピングファイルのファイル名は、名前空間を含む完全なクラス名に対応し、名前空間の区切り文字「\」がドット「。」に置き換えられている必要があります。
また、PhpDriverの代わりにDatabaseDriver(Doctrine \ ORM \ Mapping \ Driver \ DatabaseDriver.php)を使用することもできます。
于 2012-06-26T18:56:09.847 に答える