1 回答

TA貢獻2011條經驗 獲得超2個贊
以下是查找實體及其帶注釋的屬性的代碼示例。您可以將結果放在某處。但是,如果不替換帶注釋的實體,您將可以使用所有屬性,因此也許您需要創建一個偵聽器,它將偵聽 symfony 內核事件并修改您的響應數據。
$annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
$entities = [];
foreach ($entities as $entity) {
$reflectionClass = new \ReflectionClass($entity);
if (empty($annotationReader->getClassAnnotation($reflectionClass, CustomAnnotation::class))) {
continue;
}
foreach ($reflectionClass->getProperties() as $property) {
if (empty($annotationReader->getPropertyAnnotation($property, CustomPropertyAnnotation::class))) {
continue;
}
$propertyName = $property->getName();
$propertyValue = $property->getValue($entity);
}
}
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報