public function testArrayExtractOptions()
 {
     $args = ['foo' => 'bar', 'value'];
     $options = array_extract_options($args);
     $expect = ['foo' => 'bar'];
     $this->assertEquals($options, $expect);
 }
 public function authorize($action, $resource, $args = null)
 {
     $args = is_array($args) ? $args : array_slice(func_get_args(), 2);
     $message = null;
     $options = array_extract_options($args);
     if (is_array($options) && array_key_exists('message', $options)) {
         $message = $options['message'];
     } elseif (is_array($args) && array_key_exists(0, $args)) {
         list($message) = $args;
         unset($args[0]);
     }
     if ($this->cannot($action, $resource, $args)) {
         $resourceClass = $resource;
         if (is_object($resourceClass)) {
             $resourceClass = get_classname($resourceClass);
         } elseif (is_array($resourceClass)) {
             $resourceClass = head(array_values($resourceClass));
             if (is_object($resourceClass)) {
                 $resourceClass = get_classname($resourceClass);
             }
         }
         $message = $message ?: $this->getUnauthorizedMessage($action, $resourceClass);
         throw new Exceptions\AccessDenied($message, $action, $resourceClass);
     }
     return $resource;
 }
 public function __construct($controller, $name = null, $options = [])
 {
     $args = array_slice(func_get_args(), 1);
     $name = array_key_exists(0, $args) && is_string($args[0]) ? array_shift($args) : null;
     $lastArg = last($args);
     if (is_array($lastArg)) {
         $args = array_merge($args, array_extract_options($lastArg));
     }
     $options = $options ?: array_extract_options($args);
     $this->controller = $controller;
     $this->params = $controller->getParams();
     $this->name = $name;
     $this->options = $options;
 }