Example #1
0
 /**
  * POST operation on system tag collections
  *
  * @param RequestInterface $request request object
  * @param ResponseInterface $response response object
  * @return null|false
  */
 public function httpPost(RequestInterface $request, ResponseInterface $response)
 {
     $path = $request->getPath();
     // Making sure the node exists
     try {
         $node = $this->server->tree->getNodeForPath($path);
     } catch (NotFound $e) {
         return null;
     }
     if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
         $data = $request->getBodyAsString();
         $tag = $this->createTag($data, $request->getHeader('Content-Type'));
         if ($node instanceof SystemTagsObjectMappingCollection) {
             // also add to collection
             $node->createFile($tag->getId());
             $url = $request->getBaseUrl() . 'systemtags/';
         } else {
             $url = $request->getUrl();
         }
         if ($url[strlen($url) - 1] !== '/') {
             $url .= '/';
         }
         $response->setHeader('Content-Location', $url . $tag->getId());
         // created
         $response->setStatus(201);
         return false;
     }
 }