mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Get a annotaion reader by Symfony. This way the annotations get cached, and it is much faster in production.
This commit is contained in:
parent
b06a4479a6
commit
df40f712a6
1 changed files with 6 additions and 6 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue