public function head() { if (method_exists($this, 'get')) { call_user_func_array(array($this, 'get'), func_get_args()); } else { Http::setHttpResponseCode(405); } return ''; }
public function get($resourceId = null) { // call the method that populate resultGraph $this->linkData(); $hasNextPage = $this->detectIfHasNextPage(); // add metadata and weblinks to single-page resource if ($this->context->isSinglePageResource()) { // provide web links as required by LDP specifications $this->weblinks[] = WebLink::factory('http://www.w3.org/ns/ldp-paging#Page')->rel('type'); // LDP servers may provide a first page link when responding to requests with any single-page // resource as the Request-URI. $this->weblinks[] = WebLink::factory($this->context->firstPageUri())->rel('first'); // LDP servers may provide a last page link in responses to GET requests with any single-page // resource as the Request-URI. // LDP servers must provide a next page link in responses to GET requests with any single-page // resource other than the final page as the Request-URI. This is the mechanism by which clients c // an discover the URL of the next page. // LDP servers must not provide a next page link in responses to GET requests with the final // single-page resource as the Request-URI. This is the mechanism by which clients can discover // the end of the page sequence as currently known by the server. if ($hasNextPage) { $this->weblinks[] = WebLink::factory($this->context->nextPageUri())->rel('next'); } // LDP servers may provide a previous page link in responses to GET requests with any // single-page resource other than the first page as the Request-URI. // This is one mechanism by which clients can discover the URL of the previous page. // LDP servers must not provide a previous page link in responses to GET requests with the // First single-page resource as the Request-URI. This is one mechanism by which clients // can discover the beginning of the page sequence as currently known by the server. if ($this->context->getPageNum() > 0) { $this->weblinks[] = WebLink::factory($this->context->prevPageUri())->rel('prev'); } // add metadata about linked Data Single page resource $metadata = $this->templateEngine->setTemplate(' @base <{requestedUri}> . @prefix ldp-paging: <http://www.w3.org/ns/ldp-paging#> . <> a ldp-paging:Page; ldp-paging:pageOf <{pagedResourceUri}>. ')->render(); $this->resultGraph->parse($metadata, 'turtle'); } elseif ($hasNextPage) { // Server side initiated page management: // WARNING THI IMPLEMENTATION USES A LDP SPECIFICATIO FEATURE AT RISK: // LDP servers should respond with HTTP status code 333 (Returning Related) to successful // GET requests with any paged resource as the Request-URI, although any appropriate code may be used. Http::setHttpResponseCode(333); header('Location: ' . $this->context->firstPageUri()); // N.B. 333 code is not yet standarized..it is threathed as 302 by many agents // In that case you coud return withoud any other payload setup. // but if 333 will be standarized the payload is ready to serve first page } // add to result graph the metadata about Linked Data paged resource in first page // Note that this apply both for Single-Page resource and for Paged Resource if ($this->context->getPageNum() == 0) { $this->linkMetadata(); } return $this->stateTransfer($this->resultGraph, $this->weblinks); }
/** * This routine drive http caching process * Not sure to have well understand caching :-( * * Note that this routine is called by stateTransfer and may be called also from * End-Point routine after the controller exit. * * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */ public static function processor($data, $sec = 0) { // ensure not negative caching age! if ($sec < 0) { $sec = 0; } $etag = Http::setETagHeader($data); $lastModifiedOn = Http::setLastModifiedHeader($data, new \DateTime()); // this is the caching algorithm: only return data if necessary.. if (self::isNotModified($etag, $lastModifiedOn)) { // Return http status 304 Not Modified and stop data flow processing Http::setHttpResponseCode(304); return ''; // return empty data } // advertise caching policy self::setCacheControl($sec); return $data; }
public function render(Exception $e) { // build error model from Exception if ($e instanceof HttpErrorException) { $problem = $e->getHttpProblem(); } else { // guess http status code $errorCode = $e->getCode(); $isHttpErrorCode = $errorCode >= 400 && array_key_exists($errorCode, Http::$STATUS_CODES); $statusCode = $isHttpErrorCode ? $errorCode : 500; $phpErrorURI = 'http://php.net/manual/errorfunc.constants'; $problem = new HttpProblem($statusCode, null, (string) $e, $isHttpErrorCode ? null : $phpErrorURI . '#' . $errorCode, $isHttpErrorCode ? null : $phpErrorURI); } // Set header and rendering payload Http::setHttpResponseCode($problem->httpStatus); return $this->serializeHttpProblem($problem); }