Exemplo n.º 1
0
 protected function buildEndpoint()
 {
     $options = $this->options;
     if (isset($options['to']) && (is_string($options['to']) && ctype_upper(substr($options['to'], 0, 1)) || $options['to'] instanceof SerializableClosure)) {
         $this->endPoint = $options['to'];
         unset($this->options['to']);
         return;
     }
     $scope = $this->scope;
     $parts = ['namespaces' => []];
     if ($options['to']) {
         $token = new ActionToken($options['to']);
         $parts['controller'] = $token->controller();
         $parts['action'] = $token->action();
     } elseif (array_key_exists('action', $options) || isset($scope['action'])) {
         $parts['action'] = $options['action'] ?: $scope['action'];
         if (isset($scope['controller'])) {
             $parts['controller'] = $scope['controller'];
         } elseif (isset($scope['scopeLevelResource'])) {
             $parts['controller'] = $scope['scopeLevelResource']->controller();
         } else {
             throw new \UnexpectedValueException("Couldn't find controller option");
         }
     }
     if (isset($scope['namespace'])) {
         $parts['namespaces'][] = $scope['namespace'];
     }
     if (isset($options['namespace'])) {
         $parts['namespaces'][] = $options['namespace'];
     }
     $token = new ActionToken($parts);
     $this->to = $token;
     $this->controller = $token->controller();
     $this->action = $token->action();
     $this->namespaces = $token->namespaces();
 }