Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function isAllowed($role, $resource, $privilege)
 {
     if ($role instanceof IRole) {
         $role = $role->getRoleId();
     }
     if (!$resource instanceof PresenterResource) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Resource must be instance of %s, %s given.', PresenterResource::class, gettype($resource)));
     }
     $request = $resource->getRequest();
     $presenterName = $request->getPresenterName();
     $refClass = new PresenterComponentReflection($class = $this->presenterFactory->getPresenterClass($presenterName));
     if (!$refClass->hasMethod($name = Presenter::formatRenderMethod($this->getRenderName($request)))) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s is not implemented.', $class, $name));
     }
     $refMethod = $refClass->getMethod($name);
     if (!$refMethod->hasAnnotation($privilege)) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s does not have annotation %s.', $class, $name, $privilege));
     }
     return in_array($role, preg_split('#\\s+#', trim((string) $refMethod->getAnnotation($privilege))));
 }