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}\""); } } }
public function transform($object) { $class = get_class($object); $id = $this->doctrine->getManagerForClass($class)->getUnitOfWork()->getSingleIdentifierValue($object); if (null === $id) { throw new \RuntimeException("Given object of \"{$class}\" is not managed by unit of work."); } return implode('.', [Util::classToResource($class), $id]); }
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; }
/** * @test */ function it_should_convert_class_to_resource() { $this->assertSame(Util::classToResource('CamelCased\\Class\\Name'), 'camel_cased.class.name'); }
public function transform($object) { return Util::classToResource($object); }