Ejemplo n.º 1
0
 public function handleItem(RequestItem $requestItem)
 {
     try {
         $token = $requestItem->getToken();
         $method = strtolower($requestItem->getMethod());
         if ($token->isAnonymous() && !in_array($method, self::$GET_SYNONYMS)) {
             // Anonymous requests are only allowed to GET data (not create/edit/delete)
             throw new SocialSpiException("[{$method}] not allowed for anonymous users", ResponseError::$BAD_REQUEST);
         } elseif (in_array($method, self::$GET_SYNONYMS)) {
             $parameters = $requestItem->getParameters();
             if (in_array("@supportedFields", $parameters, true)) {
                 $response = $this->getSupportedFields($parameters);
             } else {
                 $response = $this->handleGet($requestItem);
             }
         } elseif (in_array($method, self::$UPDATE_SYNONYMS)) {
             $response = $this->handlePut($requestItem);
         } elseif (in_array($method, self::$DELETE_SYNONYMS)) {
             $response = $this->handleDelete($requestItem);
         } elseif (in_array($method, self::$CREATE_SYNONYMS)) {
             $response = $this->handlePost($requestItem);
         } else {
             throw new SocialSpiException("Unserviced Http method type", ResponseError::$BAD_REQUEST);
         }
     } catch (SocialSpiException $e) {
         $response = new ResponseItem($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         $response = new ResponseItem(ResponseError::$INTERNAL_ERROR, "Internal error: " . $e->getMessage());
     }
     return $response;
 }
 /**
  * Extracts the Xml entity name from the request url
  *
  * @param RequestItem $requestItem the request item
  * @param array $entryTypes the map of entries
  * @return string the request type
  */
 public static function getRequestType($requestItem, $entryTypes)
 {
     // map the Request URL to the content type to use
     $params = $requestItem->getParameters();
     if (!is_array($params)) {
         throw new Exception("Unsupported request type");
     }
     $type = false;
     foreach ($params as $key => $val) {
         if (isset($entryTypes[$key])) {
             $type = $entryTypes[$key];
             break;
         }
     }
     if (!$type) {
         throw new Exception("Unsupported request type");
     }
     return $type;
 }
 /**
  * Extracts the Atom entity name from the request url
  *
  * @param RequestItem $requestItem the request item
  * @return string the request type
  */
 private function getRequestType($requestItem)
 {
     // map the Request URL to the content type to use
     $params = $requestItem->getParameters();
     if (!is_array($params) || empty(self::$entryTypes[$params[0]])) {
         throw new Exception("Unsupported request type");
     }
     return self::$entryTypes[$params[0]];
 }