当前位置: 首页>>代码示例>>PHP>>正文


PHP Sabre_HTTP_Request::getHeader方法代码示例

本文整理汇总了PHP中Sabre_HTTP_Request::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Sabre_HTTP_Request::getHeader方法的具体用法?PHP Sabre_HTTP_Request::getHeader怎么用?PHP Sabre_HTTP_Request::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sabre_HTTP_Request的用法示例。


在下文中一共展示了Sabre_HTTP_Request::getHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCopyAndMoveInfo

 /**
  * Returns information about Copy and Move requests
  * 
  * This function is created to help getting information about the source and the destination for the 
  * WebDAV MOVE and COPY HTTP request. It also validates a lot of information and throws proper exceptions 
  * 
  * The returned value is an array with the following keys:
  *   * source - Source path
  *   * destination - Destination path
  *   * destinationExists - Wether or not the destination is an existing url (and should therefore be overwritten)
  *
  * @return array 
  */
 protected function getCopyAndMoveInfo()
 {
     $source = $this->getRequestUri();
     // Collecting the relevant HTTP headers
     if (!$this->httpRequest->getHeader('Destination')) {
         throw new Sabre_DAV_Exception_BadRequest('The destination header was not supplied');
     }
     $destination = $this->calculateUri($this->httpRequest->getHeader('Destination'));
     $overwrite = $this->httpRequest->getHeader('Overwrite');
     if (!$overwrite) {
         $overwrite = 'T';
     }
     if (strtoupper($overwrite) == 'T') {
         $overwrite = true;
     } elseif (strtoupper($overwrite) == 'F') {
         $overwrite = false;
     } else {
         throw new Sabre_DAV_Exception_BadRequest('The HTTP Overwrite header should be either T or F');
     }
     $destinationUri = dirname($destination);
     if ($destinationUri == '.') {
         $destinationUri = '';
     }
     // Collection information on relevant existing nodes
     $sourceNode = $this->tree->getNodeForPath($source);
     try {
         $destinationParent = $this->tree->getNodeForPath($destinationUri);
         if (!$destinationParent instanceof Sabre_DAV_IDirectory) {
             throw new Sabre_DAV_Exception_UnsupportedMediaType('The destination node is not a collection');
         }
     } catch (Sabre_DAV_Exception_FileNotFound $e) {
         // If the destination parent node is not found, we throw a 409
         throw new Sabre_DAV_Exception_Conflict('The destination node is not found');
     }
     try {
         $destinationNode = $this->tree->getNodeForPath($destination);
         // If this succeeded, it means the destination already exists
         // we'll need to throw precondition failed in case overwrite is false
         if (!$overwrite) {
             throw new Sabre_DAV_Exception_PreconditionFailed('The destination node already exists, and the overwrite header is set to false');
         }
     } catch (Sabre_DAV_Exception_FileNotFound $e) {
         // Destination didn't exist, we're all good
         $destinationNode = false;
     }
     // These are the three relevant properties we need to return
     return array('source' => $source, 'destination' => $destination, 'destinationExists' => $destinationNode == true, 'destinationNode' => $destinationNode);
 }
开发者ID:QuillLittlefeather,项目名称:mgm-simiangrid,代码行数:61,代码来源:Server.php

示例2: getChild

 /**
  * (non-PHPdoc)
  * @see Sabre_DAV_Collection::getChild()
  */
 public function getChild($_name)
 {
     $modelName = $this->_application->name . '_Model_' . $this->_model;
     if ($_name instanceof $modelName) {
         $object = $_name;
     } else {
         $filterClass = $this->_application->name . '_Model_' . $this->_model . 'Filter';
         $filter = new $filterClass(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_container->getId()), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name)), array('field' => 'uid', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name))))));
         $object = $this->_getController()->search($filter, null, false, false, 'sync')->getFirstRecord();
         if ($object == null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $httpRequest = new Sabre_HTTP_Request();
     // lie about existance of event of request is a PUT request from an ATTENDEE for an already existing event
     // to prevent ugly (and not helpful) error messages on the client
     if (isset($_SERVER['REQUEST_METHOD']) && $httpRequest->getMethod() == 'PUT' && $httpRequest->getHeader('If-None-Match') === '*') {
         if ($object->organizer != Tinebase_Core::getUser()->contact_id && Calendar_Model_Attender::getOwnAttender($object->attendee) !== null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $objectClass = $this->_application->name . '_Frontend_WebDAV_' . $this->_model;
     return new $objectClass($this->_container, $object);
 }
开发者ID:rodrigofns,项目名称:ExpressoLivre3,代码行数:28,代码来源:Container.php

示例3: checkPreconditions

 /**
  * This method checks the main HTTP preconditions.
  *
  * Currently these are:
  *   * If-Match
  *   * If-None-Match
  *   * If-Modified-Since
  *   * If-Unmodified-Since
  *
  * The method will return true if all preconditions are met
  * The method will return false, or throw an exception if preconditions
  * failed. If false is returned the operation should be aborted, and
  * the appropriate HTTP response headers are already set.
  *
  * Normally this method will throw 412 Precondition Failed for failures
  * related to If-None-Match, If-Match and If-Unmodified Since. It will
  * set the status to 304 Not Modified for If-Modified_since.
  *
  * If the $handleAsGET argument is set to true, it will also return 304
  * Not Modified for failure of the If-None-Match precondition. This is the
  * desired behaviour for HTTP GET and HTTP HEAD requests.
  *
  * @param bool $handleAsGET
  * @return bool
  */
 public function checkPreconditions($handleAsGET = false)
 {
     $uri = $this->getRequestUri();
     $node = null;
     $lastMod = null;
     $etag = null;
     if ($ifMatch = $this->httpRequest->getHeader('If-Match')) {
         // If-Match contains an entity tag. Only if the entity-tag
         // matches we are allowed to make the request succeed.
         // If the entity-tag is '*' we are only allowed to make the
         // request succeed if a resource exists at that url.
         try {
             $node = $this->tree->getNodeForPath($uri);
         } catch (Sabre_DAV_Exception_NotFound $e) {
             throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified and the resource did not exist', 'If-Match');
         }
         // Only need to check entity tags if they are not *
         if ($ifMatch !== '*') {
             // There can be multiple etags
             $ifMatch = explode(',', $ifMatch);
             $haveMatch = false;
             foreach ($ifMatch as $ifMatchItem) {
                 // Stripping any extra spaces
                 $ifMatchItem = trim($ifMatchItem, ' ');
                 $etag = $node->getETag();
                 if ($etag === $ifMatchItem) {
                     $haveMatch = true;
                 }
             }
             if (!$haveMatch) {
                 throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified, but none of the specified the ETags matched.', 'If-Match');
             }
         }
     }
     if ($ifNoneMatch = $this->httpRequest->getHeader('If-None-Match')) {
         // The If-None-Match header contains an etag.
         // Only if the ETag does not match the current ETag, the request will succeed
         // The header can also contain *, in which case the request
         // will only succeed if the entity does not exist at all.
         $nodeExists = true;
         if (!$node) {
             try {
                 $node = $this->tree->getNodeForPath($uri);
             } catch (Sabre_DAV_Exception_NotFound $e) {
                 $nodeExists = false;
             }
         }
         if ($nodeExists) {
             $haveMatch = false;
             if ($ifNoneMatch === '*') {
                 $haveMatch = true;
             } else {
                 // There might be multiple etags
                 $ifNoneMatch = explode(',', $ifNoneMatch);
                 $etag = $node->getETag();
                 foreach ($ifNoneMatch as $ifNoneMatchItem) {
                     // Stripping any extra spaces
                     $ifNoneMatchItem = trim($ifNoneMatchItem, ' ');
                     if ($etag === $ifNoneMatchItem) {
                         $haveMatch = true;
                     }
                 }
             }
             if ($haveMatch) {
                 if ($handleAsGET) {
                     $this->httpResponse->sendStatus(304);
                     return false;
                 } else {
                     throw new Sabre_DAV_Exception_PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
                 }
             }
         }
     }
     if (!$ifNoneMatch && ($ifModifiedSince = $this->httpRequest->getHeader('If-Modified-Since'))) {
         // The If-Modified-Since header contains a date. We
//.........这里部分代码省略.........
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:101,代码来源:Server.php

示例4: checkPreconditions

 /**
  * This method checks the main HTTP preconditions.
  *
  * Currently these are:
  *   * If-Match
  *   * If-None-Match
  *   * If-Modified-Since
  *   * If-Unmodified-Since
  *
  * The method will return true if all preconditions are met
  * The method will return false, or throw an exception if preconditions
  * failed. If false is returned the operation should be aborted, and
  * the appropriate HTTP response headers are already set.
  *
  * Normally this method will throw 412 Precondition Failed for failures
  * related to If-None-Match, If-Match and If-Unmodified Since. It will 
  * set the status to 304 Not Modified for If-Modified_since.
  *
  * If the $handleAsGET argument is set to true, it will also return 304 
  * Not Modified for failure of the If-None-Match precondition. This is the
  * desired behaviour for HTTP GET and HTTP HEAD requests.
  *
  * @return bool 
  */
 public function checkPreconditions($handleAsGET = false)
 {
     $uri = $this->getRequestUri();
     $node = null;
     $lastMod = null;
     $etag = null;
     if ($ifMatch = $this->httpRequest->getHeader('If-Match')) {
         // If-Match contains an entity tag. Only if the entity-tag
         // matches we are allowed to make the request succeed.
         // If the entity-tag is '*' we are only allowed to make the
         // request succeed if a resource exists at that url.
         try {
             $node = $this->tree->getNodeForPath($uri);
         } catch (Sabre_DAV_Exception_FileNotFound $e) {
             throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified and the resource did not exist', 'If-Match');
         }
         // Only need to check entity tags if they are not *
         if ($ifMatch !== '*') {
             // The Etag is surrounded by double-quotes, so those must be
             // stripped.
             $ifMatch = trim($ifMatch, '"');
             $etag = $node->getETag();
             if ($etag !== $ifMatch) {
                 throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified, but the ETag did not match', 'If-Match');
             }
         }
     }
     if ($ifNoneMatch = $this->httpRequest->getHeader('If-None-Match')) {
         // The If-None-Match header contains an etag.
         // Only if the ETag does not match the current ETag, the request will succeed
         // The header can also contain *, in which case the request
         // will only succeed if the entity does not exist at all.
         $nodeExists = true;
         if (!$node) {
             try {
                 $node = $this->tree->getNodeForPath($uri);
             } catch (Sabre_DAV_Exception_FileNotFound $e) {
                 $nodeExists = false;
             }
         }
         if ($nodeExists) {
             // The Etag is surrounded by double-quotes, so those must be
             // stripped.
             $ifNoneMatch = trim($ifNoneMatch, '"');
             if ($ifNoneMatch === '*' || ($etag = $node->getETag()) && $etag === $ifNoneMatch) {
                 if ($handleAsGET) {
                     $this->httpResponse->sendStatus(304);
                     return false;
                 } else {
                     throw new Sabre_DAV_Exception_PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
                 }
             }
         }
     }
     if (!$ifNoneMatch && ($ifModifiedSince = $this->httpRequest->getHeader('If-Modified-Since'))) {
         // The If-Modified-Since header contains a date. We
         // will only return the entity if it has been changed since
         // that date. If it hasn't been changed, we return a 304
         // header
         // Note that this header only has to be checked if there was no If-None-Match header
         // as per the HTTP spec.
         $date = new DateTime($ifModifiedSince);
         if (is_null($node)) {
             $node = $this->tree->getNodeForPath($uri);
         }
         $lastMod = $node->getLastModified();
         if ($lastMod) {
             $lastMod = new DateTime('@' . $lastMod);
             if ($lastMod <= $date) {
                 $this->httpResponse->sendStatus(304);
                 return false;
             }
         }
     }
     if ($ifUnmodifiedSince = $this->httpRequest->getHeader('If-Unmodified-Since')) {
         // The If-Unmodified-Since will allow allow the request if the
//.........这里部分代码省略.........
开发者ID:ngocanh,项目名称:pimcore,代码行数:101,代码来源:Server.php

示例5: testGetNonExistantHeader

 function testGetNonExistantHeader()
 {
     $this->assertNull($this->request->getHeader('doesntexist'));
     $this->assertNull($this->request->getHeader('Content-Length'));
 }
开发者ID:ZerGabriel,项目名称:friendica-addons,代码行数:5,代码来源:RequestTest.php


注:本文中的Sabre_HTTP_Request::getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。