私はGeneric
エンティティリファレンスを扱うフォームタイプを構築しています。これは、あるエンティティを他のエンティティと関連付けることを可能にします。私はすべてのphpを検索するFinder
コンポーネントを使用してきたこれまでのところDoctrineからすべてのマップされたエンティティクラスを取得するには?
class GenericType extends AbstractType
{
// ...
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('entityClass', ChoiceType::class, [
'choices' => $this->getAllMappedEntityClasses(),
]);
// ...
}
private function getAllMappedEntityClasses()
{
// populating $choices with all current entity classes
return $choices;
}
}
:
class Generic
{
// ...
/**
* @ORM\Column(type="string")
*/
$private $entityClass;
}
マイフォームタイプがこれです:
このGeneric
は、参照先エンティティクラスを保存$entityClass
性質を持っていますそれぞれのEntity
ディレクトリ内のクラスを手で、$class = $file->getBasename('.php');
とrequire_once $file;
まで私はすべてのクラスを与えます。しかし、私はコードサンプルでそれを省略している理由です、それは恐ろしい回避策だと認識しています:(
現在、私のアプリケーションにマッピングされたエンティティクラスのリストを取得するための別の方法はありますか?思考?