コード例 #1
0
 public function __construct(array $params, $mainEntity)
 {
     $this->at = RestUrlParams::parseTimestamp(RestUrlParams::extractValue($params, RestUrlParams::AT));
     if ($this->at == RestUrlParams::ALL_TIMES) {
         $this->at = self::ALL_TIMES;
     }
     $this->published = RestUrlParams::parseBoolean(RestUrlParams::extractValue($params, RestUrlParams::PUBLISHED));
     $this->queryParamsMap = array();
     $this->scopeMap = array();
     if ($mainEntity != NULL) {
         foreach ($params as $paramName => $paramValue) {
             // Parameters can be specified with or without entity-prefix, e.g. 'entity/property=value' or just
             // 'property=value'. Check if an entity-prefix is provided.
             $entityName = NULL;
             $propertyName = NULL;
             $paramNameParts = explode(RestUrlParams::ENTITY_SEPARATOR, $paramName);
             if (count($paramNameParts) == 1) {
                 // It's like 'property=value'.
                 $entityName = $mainEntity->getName();
                 $propertyName = $paramName;
             } else {
                 if (count($paramNameParts) == 2) {
                     // It's like 'entity/property=value'.
                     $entityName = $paramNameParts[0];
                     $propertyName = $paramNameParts[1];
                 } else {
                     throw new Exception("Illegal query parameter '{$paramName}'.");
                 }
             }
             // If it's a scope parameter...
             if (strcasecmp($propertyName, RestUrlParams::SCOPE) == 0) {
                 // ...then parse it.
                 $this->scopeMap[$entityName] = Scope::parseValue($paramValue);
             } else {
                 // ...else add the value to the map at the correct entity-entry.
                 if (!array_key_exists($entityName, $this->queryParamsMap)) {
                     $this->queryParamsMap[$entityName] = array();
                 }
                 // If $paramName is 'id'...
                 if (strcasecmp($propertyName, RestUrlParams::ID) == 0) {
                     // ...then check if this is allowed for the given entity...
                     if (!$mainEntity->isObjectEntity()) {
                         throw new Exception("Cannot fetch entity '" . $mainEntity->getName() . "' by id.");
                     }
                     // ...and apply the correct property name and value.
                     $propertyName = $mainEntity->getObjectIdColumnName();
                     $paramValue = explode(RestUrlParams::ID_SEPARATOR, $paramValue);
                 }
                 $this->queryParamsMap[$entityName][$propertyName] = $paramValue;
             }
         }
     }
 }
コード例 #2
0
 public static function isFetchParam($paramName)
 {
     if (self::$FETCH_PARAM_NAMES == NULL) {
         self::$FETCH_PARAM_NAMES = array(self::AT, self::PUBLISHED, self::SCOPE, self::SKIP_BINARIES, self::ID);
     }
     foreach (self::$FETCH_PARAM_NAMES as $validParamName) {
         if (strcasecmp($paramName, $validParamName) == 0) {
             return TRUE;
         }
     }
     return FALSE;
 }
コード例 #3
0
 /**
  * Fetches a single object of the given entity and id, applying the query parameters to limit the resultset.
  * The fetched data is added as the root element of the given XML document.
  * 
  * @param Entity $entity
  * @param type $id
  * @param array $params
  * @params Scope $scope
  * @params DOMDocument $domDoc
  * @params $skipBinaries
  * @return DOMElement with requested data or NULL if not found
  */
 public function getObjectTree(Entity $entity, $id, array $params, DOMDocument $domDoc)
 {
     $scope = Scope::parseValue(RestUrlParams::extractValue($params, RestUrlParams::SCOPE));
     $skipBinaries = RestUrlParams::parseBoolean(RestUrlParams::extractValue($params, RestUrlParams::SKIP_BINARIES));
     $queryContext = new QueryContext($params, $entity);
     $xmlElementsWithState = array();
     $this->fetchObjects($entity, $id, $queryContext, $scope, $skipBinaries, $domDoc, $domDoc, $xmlElementsWithState);
     $xmlResult = $domDoc->documentElement;
     if ($xmlResult != NULL) {
         $this->setLifecycleTimestamps($xmlElementsWithState);
         $this->setTimestamp($xmlResult, XmlConstants::AT, $queryContext->getParameterAt());
     }
     return $xmlResult;
 }
コード例 #4
0
 private function processQueryParams(Schema $schema, $mainEntity)
 {
     // Get rid of any 'PHPSESSION' and cookie params.
     RestUrlParams::extractValue($this->params, session_name());
     // Create/restore the temporaryIdMap.
     $storedTemporaryIds = NULL;
     if (isset($_SESSION[$this->sessionId])) {
         $storedTemporaryIds = TemporaryIdMap::deserializeTemporaryIds($schema, $_SESSION[$this->sessionId]);
     }
     $this->temporaryIdMap = new TemporaryIdMap($storedTemporaryIds);
     // Validate that prefixed parameters refer to existing entities.
     foreach ($this->params as $paramName => &$paramValue) {
         if (RestUrlParams::isFetchParam($paramName)) {
             continue;
         }
         $paramNameParts = explode(RestUrlParams::ENTITY_SEPARATOR, $paramName);
         $entity = NULL;
         $queryParam = NULL;
         if (count($paramNameParts) == 1) {
             if ($mainEntity == NULL) {
                 //                    error_log("Ignoring unknown query parameter: '$paramName=$paramValue'.");
                 unset($this->params[$paramName]);
                 continue;
             }
             $entity = $mainEntity;
             $queryParam = $paramNameParts[0];
         } else {
             // Check if the specified entity exists.
             $entity = $schema->getObjectEntity($paramNameParts[0], false);
             if ($entity == NULL) {
                 throw new Exception("Unknown entity '{$paramNameParts['0']}' in query parameters.", RestResponse::CLIENT_ERROR);
             }
             $queryParam = $paramNameParts[1];
         }
         // If one or more ID's are specified...
         if (strcasecmp($queryParam, RestUrlParams::ID) == 0) {
             // ...then substitute any temporary ID with its persisted counterpart.
             $persistedIds = array();
             foreach (explode(RestUrlParams::ID_SEPARATOR, $paramValue) as $id) {
                 $persistedIds[] = $this->temporaryIdMap->getPersistedId($entity, $id);
             }
             $paramValue = implode(RestUrlParams::ID_SEPARATOR, $persistedIds);
         }
     }
 }