/**
  * @return JsonResponse
  */
 public function getAction()
 {
     $securityFacade = $this->securityFacade;
     $annotations = $this->aclProvider->getAnnotations();
     $result = [];
     foreach ($annotations as $annotation) {
         $result[$annotation->getId()] = $securityFacade->isGranted($annotation->getId());
     }
     return new JsonResponse($result);
 }
 public function testFindAndGetAnnotation()
 {
     $this->loader->expects($this->once())->method('load')->will($this->returnCallback(function ($storage) {
         /** @var AclAnnotationStorage $storage */
         $storage->add(new AclAnnotation(['id' => 'test', 'type' => 'entity']), 'SomeClass', 'SomeMethod');
     }));
     $this->assertEquals('test', $this->provider->findAnnotationById('test')->getId());
     $this->assertNull($this->provider->findAnnotationById('unknown'));
     $this->assertEquals('test', $this->provider->findAnnotation('SomeClass', 'SomeMethod')->getId());
     $this->assertNull($this->provider->findAnnotation('SomeClass', 'UnknownMethod'));
     $this->assertNull($this->provider->findAnnotation('UnknownClass', 'SomeMethod'));
     $this->assertCount(1, $this->provider->getAnnotations());
     $this->assertCount(1, $this->provider->getAnnotations('entity'));
     $this->assertCount(0, $this->provider->getAnnotations('action'));
 }
Пример #3
0
 /**
  * Loads metadata and save them in cache
  */
 protected function loadMetadata()
 {
     $data = array();
     foreach ($this->annotationProvider->getAnnotations('action') as $annotation) {
         $data[$annotation->getId()] = new ActionMetadata($annotation->getId(), $annotation->getGroup(), $annotation->getLabel());
     }
     if ($this->cache) {
         $this->cache->save(self::CACHE_KEY, $data);
     }
     $this->localCache = $data;
 }
 /**
  * Makes sure that metadata are loaded
  */
 protected function ensureMetadataLoaded()
 {
     if ($this->localCache === null) {
         $data = null;
         if ($this->cache) {
             $data = $this->cache->fetch(self::CACHE_KEY);
         }
         if (!$data) {
             $data = [];
             foreach ($this->annotationProvider->getAnnotations('action') as $annotation) {
                 $data[$annotation->getId()] = new ActionMetadata($annotation->getId(), $annotation->getGroup(), $annotation->getLabel());
             }
             if ($this->cache) {
                 $this->cache->save(self::CACHE_KEY, $data);
             }
         }
         $this->localCache = $data;
     }
 }