Example #1
0
 public function __construct($hostInfo)
 {
     $this->_hostInfo = $hostInfo;
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_PROTOCOL] = $this->_hostInfo['AbsoluteRequestUri']->getScheme();
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_HOST] = $this->_hostInfo['AbsoluteRequestUri']->getHost() . ':' . $this->_hostInfo['AbsoluteRequestUri']->getPort();
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_URI] = $this->_hostInfo['AbsoluteRequestUri']->getPath();
     if (array_key_exists('DataServiceVersion', $this->_hostInfo)) {
         $_SERVER[ODataConstants::ODATASERVICEVERSION] = $this->_hostInfo['DataServiceVersion']->toString();
     }
     if (array_key_exists('MaxDataServiceVersion', $this->_hostInfo)) {
         $_SERVER[ODataConstants::ODATAMAXSERVICEVERSION] = $this->_hostInfo['MaxDataServiceVersion']->toString();
     }
     if (array_key_exists('RequestIfMatch', $this->_hostInfo)) {
         $_SERVER[ODataConstants::HTTPREQUEST_HEADER_IFMATCH] = $this->_hostInfo['RequestIfMatch'];
     }
     if (array_key_exists('RequestIfNoneMatch', $this->_hostInfo)) {
         $_SERVER[ODataConstants::HTTPREQUEST_HEADER_IFNONE] = $this->_hostInfo['RequestIfNoneMatch'];
     }
     if (array_key_exists('QueryString', $this->_hostInfo)) {
         $_SERVER[ODataConstants::HTTPREQUEST_HEADER_QUERY_STRING] = $this->_hostInfo['QueryString'];
     }
     //print_r($_SERVER);
     parent::__construct();
     if (array_key_exists('AbsoluteServiceUri', $this->_hostInfo)) {
         $this->setAbsoluteServiceUri($this->_hostInfo['AbsoluteServiceUri']->getUrlAsString());
     }
 }
Example #2
0
 /**
  * Gets the service name from the request uri.
  * 
  * @return string
  */
 private function _getServiceNameFromRequestUri()
 {
     $url = $this->_dataServiceHost->getAbsoluteRequestUri();
     $segments = $url->getSegments();
     for ($i = count($segments) - 1; $i >= 0; $i--) {
         if (stripos($segments[$i], '.svc') !== false) {
             return $segments[$i];
         }
     }
     return null;
 }
Example #3
0
 /**
  * For the given entry object compare it's eTag (if it has eTag properties)
  * with current eTag request headers (if it present).
  * 
  * @param mixed        &$entryObject             entity resource for which etag 
  *                                               needs to be checked.
  * @param ResourceType &$resourceType            Resource type of the entry 
  *                                               object.
  * @param boolean      &$needToSerializeResponse On return, this will contain 
  *                                               True if response needs to be
  *                                               serialized, False otherwise.
  *                                              
  * @return string/NULL The ETag for the entry object if it has eTag properties 
  *                     NULL otherwise.
  */
 protected function compareETag(&$entryObject, ResourceType &$resourceType, &$needToSerializeResponse)
 {
     $needToSerializeResponse = true;
     $eTag = null;
     $ifMatch = $this->_dataServiceHost->getRequestIfMatch();
     $ifNoneMatch = $this->_dataServiceHost->getRequestIfNoneMatch();
     if (is_null($entryObject)) {
         if (!is_null($ifMatch)) {
             ODataException::createPreConditionFailedError(Messages::dataServiceETagNotAllowedForNonExistingResource());
         }
         return null;
     }
     if ($this->_dataServiceConfiguration->getValidateETagHeader() && !$resourceType->hasETagProperties()) {
         if (!is_null($ifMatch) || !is_null($ifNoneMatch)) {
             // No eTag properties but request has eTag headers, bad request
             ODataException::createBadRequestError(Messages::dataServiceNoETagPropertiesForType());
         }
         // We need write the response but no eTag header
         return null;
     }
     if (!$this->_dataServiceConfiguration->getValidateETagHeader()) {
         // Configuration says do not validate ETag so we will not write ETag header in the
         // response even though the requested resource support it
         return null;
     }
     if (is_null($ifMatch) && is_null($ifNoneMatch)) {
         // No request eTag header, we need to write the response
         // and eTag header
     } else {
         if (strcmp($ifMatch, '*') == 0) {
             // If-Match:* => we need to write the response and eTag header
         } else {
             if (strcmp($ifNoneMatch, '*') == 0) {
                 // if-None-Match:* => Do not write the response (304 not modified),
                 // but write eTag header
                 $needToSerializeResponse = false;
             } else {
                 $eTag = $this->getETagForEntry($entryObject, $resourceType);
                 // Note: The following code for attaching the prefix W\"
                 // and the suffix " can be done in getETagForEntry function
                 // but that is causing an issue in Linux env where the
                 // firefix browser is unable to parse the ETag in this case.
                 // Need to follow up PHP core devs for this.
                 $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"';
                 if (!is_null($ifMatch)) {
                     if (strcmp($eTag, $ifMatch) != 0) {
                         // Requested If-Match value does not match with current
                         // eTag Value then pre-condition error
                         // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
                         ODataException::createPreConditionFailedError(Messages::dataServiceETagValueDoesNotMatch());
                     }
                 } else {
                     if (strcmp($eTag, $ifNoneMatch) == 0) {
                         //304 not modified, but in write eTag header
                         $needToSerializeResponse = false;
                     }
                 }
             }
         }
     }
     if (is_null($eTag)) {
         $eTag = $this->getETagForEntry($entryObject, $resourceType);
         // Note: The following code for attaching the prefix W\"
         // and the suffix " can be done in getETagForEntry function
         // but that is causing an issue in Linux env where the
         // firefix browser is unable to parse the ETag in this case.
         // Need to follow up PHP core devs for this.
         $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"';
     }
     return $eTag;
 }
Example #4
0
 public function validateQueryParameters($queryString = null)
 {
     parent::validateQueryParameters($this->_hostInfo['QueryString']);
 }