protected function action()
 {
     $this->actionResult['resource'] = $this->resourceDO->toArray();
     $this->actionResult['exists'] = $this->isExist();
     $this->actionResult['options'] = $this->findOptions();
     array_walk($this->actionResult['options'], [$this, 'addLinkToOption'], ['resourceDO' => $this->resourceDO]);
 }
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     parent::__invoke($request, $response, $next);
     if ($this->isSupportedResponse($response)) {
         $uri = $this->getUri($this->resourceDO);
         $data = ['resource' => $this->resourceDO->toArray(), 'uri' => $uri];
         if (!empty($data)) {
             $headers = $response->getHeaders();
             $headers['Content-Type'] = 'application/json';
             // here is relative link without host url
             $headers['Link'] = '<' . rawurlencode($uri) . '>; rel="canonical"';
             $response = $this->getResponseObject($data, $response->getStatusCode(), $headers);
         }
     }
     return $next($request, $response);
 }
Example #3
0
 /**
  * @param string $message
  * @param integer $code
  * @param null|ResourceDOInterface $resourceDO
  * @return array
  */
 protected function getErrorArray($message, $code, ResourceDOInterface $resourceDO = null)
 {
     $error = ['error' => ['title' => $message, 'code' => $code]];
     if ($resourceDO) {
         $error['error']['detail']['resource'] = $resourceDO->toArray();
     }
     return $error;
 }