From df40f712a6e54c8088c81478000f2aa85f68b9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 21 Mar 2019 13:09:42 +0100 Subject: [PATCH] Get a annotaion reader by Symfony. This way the annotations get cached, and it is much faster in production. --- .../EntityListeners/ElementPermissionListener.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Security/EntityListeners/ElementPermissionListener.php b/src/Security/EntityListeners/ElementPermissionListener.php index e7b09647..5b18d0eb 100644 --- a/src/Security/EntityListeners/ElementPermissionListener.php +++ b/src/Security/EntityListeners/ElementPermissionListener.php @@ -31,7 +31,7 @@ namespace App\Security\EntityListeners; use App\Security\Annotations\ColumnSecurity; use App\Entity\DBElement; -use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Mapping\PostLoad; @@ -49,10 +49,12 @@ use Symfony\Component\Security\Core\Security; class ElementPermissionListener { protected $security; + protected $reader; - public function __construct(Security $security) + public function __construct(Security $security, Reader $reader) { $this->security = $security; + $this->reader = $reader; } /** @@ -67,13 +69,12 @@ class ElementPermissionListener //Read Annotations and properties. $reflectionClass = new ReflectionClass($element); $properties = $reflectionClass->getProperties(); - $reader = new AnnotationReader(); foreach ($properties as $property) { /** * @var ColumnSecurity */ - $annotation = $reader->getPropertyAnnotation($property, + $annotation = $this->reader->getPropertyAnnotation($property, ColumnSecurity::class); //Check if user is allowed to read info, otherwise apply placeholder @@ -93,13 +94,12 @@ class ElementPermissionListener { $reflectionClass = new ReflectionClass($element); $properties = $reflectionClass->getProperties(); - $reader = new AnnotationReader(); foreach ($properties as $property) { /** * @var ColumnSecurity */ - $annotation = $reader->getPropertyAnnotation($property, + $annotation = $this->reader->getPropertyAnnotation($property, ColumnSecurity::class); if (null !== $annotation) {