Ejemplo n.º 1
0
 /**
  * @param string $entity
  * @param string $action
  * @param array $params
  * @param bool $throws whether we should pass any exceptions for authorization failures
  *
  * @throws API_Exception
  * @throws Exception
  * @return bool TRUE or FALSE depending on the outcome of the authorization check
  */
 function runPermissionCheck($entity, $action, $params, $throws = FALSE)
 {
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $dispatcher->addSubscriber(new \Civi\API\Subscriber\PermissionCheck());
     $kernel = new \Civi\API\Kernel($dispatcher);
     $apiRequest = \Civi\API\Request::create($entity, $action, $params, NULL);
     try {
         $kernel->authorize(NULL, $apiRequest);
         return TRUE;
     } catch (\API_Exception $e) {
         $extra = $e->getExtraParams();
         if (!$throws && $extra['error_code'] == API_Exception::UNAUTHORIZED) {
             return FALSE;
         } else {
             throw $e;
         }
     }
 }