public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     list($ctrl, $action) = $controller;
     $ref = new \ReflectionClass($ctrl);
     $annotations = $this->reader->getMethodAnnotations($ref->getMethod($action));
     $acl = current(array_filter($annotations, function ($annotation) {
         return $annotation instanceof ACL;
     }));
     if ($acl) {
         if (strlen($acl->value)) {
             $parts = explode('.', $acl->value);
             $action = array_pop($parts);
             $resource = implode('.', $parts);
         } else {
             $resource = Util::classToResource($ctrl);
             $action = Util::underscore(preg_replace('/Action$/', '', $action));
         }
         if (!($allowed = $this->dm->isGranted($action, $resource))) {
             throw new AccessDeniedHttpException("User is not allowed to \"{$action}\" resource: \"{$resource}\"");
         }
     }
 }
 private function parse(\ReflectionClass $controller, $action)
 {
     $resources = [];
     $annotations = $this->reader->getMethodAnnotations($controller->getMethod($action));
     foreach ($annotations as $annotation) {
         if (!$annotation instanceof ACL) {
             continue;
         }
         if (null !== $annotation->value && $annotation->value != "") {
             $resources[] = $annotation->value;
             continue;
         }
         $resources[] = implode('.', [Util::classToResource($controller->getName()), Util::underscore(preg_replace('/Action$/', '', $action))]);
     }
     return $resources;
 }
Exemple #3
0
 /**
  * @test
  */
 function it_should_convert_camelcased_words_to_underscored_lowercased()
 {
     $this->assertSame('camel_cased_class_name', Util::underscore('CamelCasedClassName'));
 }