/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testStorage()
 {
     $storage = new AclAnnotationStorage();
     $storage->add(new AclAnnotation(['id' => 'annotation_wo_bindings', 'type' => 'entity']));
     $storage->add(new AclAnnotation(['id' => 'annotation_with_class_bindings', 'type' => 'entity']), 'Acme\\SomeClass');
     $storage->add(new AclAnnotation(['id' => 'annotation_with_method_bindings', 'type' => 'entity']), 'Acme\\SomeClass', 'SomeMethod');
     $storage->add(new AclAnnotation(['id' => 'annotation1', 'type' => 'entity']));
     $storage->addAncestor(new AclAnnotationAncestor(['value' => 'annotation1']), 'Acme\\SomeClass1');
     $storage->add(new AclAnnotation(['id' => 'annotation2', 'type' => 'entity']));
     $storage->addAncestor(new AclAnnotationAncestor(['value' => 'annotation2']), 'Acme\\SomeClass1', 'SomeMethod');
     $this->assertEquals('annotation_wo_bindings', $storage->findById('annotation_wo_bindings')->getId());
     $this->assertEquals('annotation_with_class_bindings', $storage->findById('annotation_with_class_bindings')->getId());
     $this->assertEquals('annotation_with_class_bindings', $storage->find('Acme\\SomeClass')->getId());
     $this->assertEquals('annotation_with_method_bindings', $storage->findById('annotation_with_method_bindings')->getId());
     $this->assertEquals('annotation_with_method_bindings', $storage->find('Acme\\SomeClass', 'SomeMethod')->getId());
     $this->assertEquals('annotation1', $storage->findById('annotation1')->getId());
     $this->assertEquals('annotation1', $storage->find('Acme\\SomeClass1')->getId());
     $this->assertEquals('annotation2', $storage->findById('annotation2')->getId());
     $this->assertEquals('annotation2', $storage->find('Acme\\SomeClass1', 'SomeMethod')->getId());
     // test 'has' method
     $this->assertTrue($storage->has('Acme\\SomeClass'));
     $this->assertFalse($storage->has('Acme\\UnknownClass'));
     $this->assertTrue($storage->has('Acme\\SomeClass', 'SomeMethod'));
     $this->assertFalse($storage->has('Acme\\SomeClass', 'UnknownMethod'));
     $this->assertFalse($storage->has('Acme\\UnknownClass', 'SomeMethod'));
     // test annotation override
     $this->assertEquals('entity', $storage->findById('annotation2')->getType());
     $storage->add(new AclAnnotation(['id' => 'annotation2', 'type' => 'action']));
     $this->assertEquals('action', $storage->findById('annotation2')->getType());
     // test duplicate bindings
     $storage->addAncestor(new AclAnnotationAncestor(['value' => 'annotation2']), 'Acme\\SomeClass1', 'SomeMethod');
     $this->setExpectedException('\\RuntimeException');
     $storage->addAncestor(new AclAnnotationAncestor(['value' => 'annotation1']), 'Acme\\SomeClass1', 'SomeMethod');
 }
 /**
  * Loads ACL annotations from PHP files
  *
  * @param AclAnnotationStorage $storage
  */
 public function load(AclAnnotationStorage $storage)
 {
     $configLoader = OroSecurityExtension::getAclAnnotationLoader();
     $resources = $configLoader->load();
     foreach ($resources as $resource) {
         foreach ($resource->data as $file) {
             $className = $this->getClassName($file);
             if ($className !== null) {
                 $reflection = $this->getReflectionClass($className);
                 // read annotations from class
                 $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS);
                 if ($annotation) {
                     $storage->add($annotation, $reflection->getName());
                 } else {
                     $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS);
                     if ($ancestor) {
                         $storage->addAncestor($ancestor, $reflection->getName());
                     }
                 }
                 // read annotations from methods
                 foreach ($reflection->getMethods() as $reflectionMethod) {
                     $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS);
                     if ($annotation) {
                         $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName());
                     } else {
                         $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS);
                         if ($ancestor) {
                             $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName());
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Loads ACL annotations from PHP files
  *
  * @param AclAnnotationStorage $storage
  */
 public function load(AclAnnotationStorage $storage)
 {
     if (!empty($this->subDirs)) {
         $directories = [];
         foreach ($this->bundleDirectories as $bundleDir) {
             foreach ($this->subDirs as $subDir) {
                 $dir = $bundleDir . DIRECTORY_SEPARATOR . $subDir;
                 if (is_dir($dir)) {
                     $directories[] = $dir;
                 }
             }
         }
     } else {
         $directories = $this->bundleDirectories;
     }
     $files = $this->findFiles('*.php', $directories);
     foreach ($files as $file) {
         $className = $this->getClassName($file);
         if ($className !== null) {
             $reflection = $this->getReflectionClass($className);
             // read annotations from class
             $annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS);
             if ($annotation) {
                 $storage->add($annotation, $reflection->getName());
             } else {
                 $ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS);
                 if ($ancestor) {
                     $storage->addAncestor($ancestor, $reflection->getName());
                 }
             }
             // read annotations from methods
             foreach ($reflection->getMethods() as $reflectionMethod) {
                 $annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS);
                 if ($annotation) {
                     $storage->add($annotation, $reflection->getName(), $reflectionMethod->getName());
                 } else {
                     $ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS);
                     if ($ancestor) {
                         $storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName());
                     }
                 }
             }
         }
     }
 }