/** * Query for a related resource set or resource set reference pointed by the * given segment descriptor and update the descriptor with the result. * * @param SegmentDescriptor &$segmentDescriptor Describes the related resource * to query. * * @return void */ private function _handleSegmentTargetsToRelatedResource(SegmentDescriptor &$segmentDescriptor) { $projectedProperty = $segmentDescriptor->getProjectedProperty(); $projectedPropertyKind = $projectedProperty->getKind(); if ($projectedPropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE) { if ($segmentDescriptor->isSingleResult()) { $entityInstance = $this->_provider->getResourceFromRelatedResourceSet($segmentDescriptor->getPrevious()->getTargetResourceSetWrapper()->getResourceSet(), $segmentDescriptor->getPrevious()->getResult(), $segmentDescriptor->getTargetResourceSetWrapper()->getResourceSet(), $projectedProperty, $segmentDescriptor->getKeyDescriptor()); $segmentDescriptor->setResult($entityInstance); } else { $entityInstances = $this->_provider->getRelatedResourceSet($segmentDescriptor->getPrevious()->getTargetResourceSetWrapper()->getResourceSet(), $segmentDescriptor->getPrevious()->getResult(), $segmentDescriptor->getTargetResourceSetWrapper()->getResourceSet(), $segmentDescriptor->getProjectedProperty(), $this->_requestDescription->getInternalFilterInfo(), null, null, null, null); $segmentDescriptor->setResult($entityInstances); } } else { if ($projectedPropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE) { $entityInstance = $this->_provider->getRelatedResourceReference($segmentDescriptor->getPrevious()->getTargetResourceSetWrapper()->getResourceSet(), $segmentDescriptor->getPrevious()->getResult(), $segmentDescriptor->getTargetResourceSetWrapper()->getResourceSet(), $segmentDescriptor->getProjectedProperty()); $segmentDescriptor->setResult($entityInstance); } else { //Unexpected state } } }
/** * Create SegmentDescriptor for the first segment * * @param string $segmentIdentifier The identifier part of the * first segment * @param string $keyPredicate The predicate part of the first * segment if any else NULL * @param boolean $checkRights Whether to check the rights on * this segment * * @return SegmentDescriptor Descriptor for the first segment * * @throws ODataException Exception if any validation fails */ private function _createFirstSegmentDescriptor($segmentIdentifier, $keyPredicate, $checkRights) { $descriptor = new SegmentDescriptor(); $descriptor->setIdentifier($segmentIdentifier); if ($segmentIdentifier === ODataConstants::URI_METADATA_SEGMENT) { $this->_assertion(is_null($keyPredicate)); $descriptor->setTargetKind(RequestTargetKind::METADATA); return $descriptor; } if ($segmentIdentifier === ODataConstants::URI_BATCH_SEGMENT) { $this->_assertion(is_null($keyPredicate)); $descriptor->setTargetKind(RequestTargetKind::BATCH); return $descriptor; } if ($segmentIdentifier === ODataConstants::URI_COUNT_SEGMENT) { ODataException::createBadRequestError(Messages::segmentParserSegmentNotAllowedOnRoot(ODataConstants::URI_COUNT_SEGMENT)); } if ($segmentIdentifier === ODataConstants::URI_LINK_SEGMENT) { ODataException::createBadRequestError(Messages::segmentParserSegmentNotAllowedOnRoot(ODataConstants::URI_LINK_SEGMENT)); } $resourceSetWrapper = $this->_providerWrapper->resolveResourceSet($segmentIdentifier); if ($resourceSetWrapper === null) { ODataException::createResourceNotFoundError($segmentIdentifier); } $descriptor->setTargetResourceSetWrapper($resourceSetWrapper); $descriptor->setTargetResourceType($resourceSetWrapper->getResourceType()); $descriptor->setTargetSource(RequestTargetSource::ENTITY_SET); $descriptor->setTargetKind(RequestTargetKind::RESOURCE); if ($keyPredicate !== null) { $keyDescriptor = $this->_createKeyDescriptor($segmentIdentifier . '(' . $keyPredicate . ')', $resourceSetWrapper->getResourceType(), $keyPredicate); $descriptor->setKeyDescriptor($keyDescriptor); if (!$keyDescriptor->isEmpty()) { $descriptor->setSingleResult(true); } } if ($checkRights) { $resourceSetWrapper->checkResourceSetRightsForRead($descriptor->isSingleResult()); } return $descriptor; }
/** * Checks whether etag headers are allowed for this request. * * @return boolean True if ETag header (If-Match or If-NoneMatch) * is allowed for the request, False otherwise. */ public function isETagHeaderAllowed() { return $this->_lastSegmentDescriptor->isSingleResult() && $this->_requestCountOption != RequestCountOption::VALUE_ONLY && !$this->isLinkUri() && (is_null($this->_rootProjectionNode) || !$this->_rootProjectionNode->isExpansionSpecified()); }