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


PHP Zend_Gdata_App::getHttpMethodOverride方法代码示例

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


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

示例1: prepareRequest

 /**
  * Provides pre-processing for HTTP requests to APP services.
  *
  * 1. Checks the $data element and, if it's an entry, extracts the XML,
  *    multipart data, edit link (PUT,DELETE), etc.
  * 2. If $data is a string, sets the default content-type  header as
  *    'application/atom+xml' if it's not already been set.
  * 3. Adds a x-http-method override header and changes the HTTP method
  *    to 'POST' if necessary as per getHttpMethodOverride()
  *
  * @param string $method The HTTP method for the request - 'GET', 'POST',
  *                       'PUT', 'DELETE'
  * @param string $url The URL to which this request is being performed,
  *                    or null if found in $data
  * @param array $headers An associative array of HTTP headers for this
  *                       request
  * @param mixed $data The Zend_Gdata_App_Entry or XML for the
  *                    body of the request
  * @param string $contentTypeOverride The override value for the
  *                                    content type of the request body
  * @return array An associative array containing the determined
  *               'method', 'url', 'data', 'headers', 'contentType'
  */
 public function prepareRequest($method, $url = null, $headers = array(), $data = null, $contentTypeOverride = null)
 {
     // As a convenience, if $headers is null, we'll convert it back to
     // an empty array.
     if ($headers === null) {
         $headers = array();
     }
     $rawData = null;
     $finalContentType = null;
     if ($url == null) {
         $url = $this->_defaultPostUri;
     }
     if (is_string($data)) {
         $rawData = $data;
         if ($contentTypeOverride === null) {
             $finalContentType = 'application/atom+xml';
         }
     } elseif ($data instanceof Zend_Gdata_App_MediaEntry) {
         $rawData = $data->encode();
         if ($data->getMediaSource() !== null) {
             $finalContentType = $rawData->getContentType();
             $headers['MIME-version'] = '1.0';
             $headers['Slug'] = $data->getMediaSource()->getSlug();
         } else {
             $finalContentType = 'application/atom+xml';
         }
         if ($method == 'PUT' || $method == 'DELETE') {
             $editLink = $data->getEditLink();
             if ($editLink != null && $url == null) {
                 $url = $editLink->getHref();
             }
         }
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $rawData = $data->saveXML();
         $finalContentType = 'application/atom+xml';
         if ($method == 'PUT' || $method == 'DELETE') {
             $editLink = $data->getEditLink();
             if ($editLink != null) {
                 $url = $editLink->getHref();
             }
         }
     } elseif ($data instanceof Zend_Gdata_App_MediaSource) {
         $rawData = $data->encode();
         if ($data->getSlug() !== null) {
             $headers['Slug'] = $data->getSlug();
         }
         $finalContentType = $data->getContentType();
     }
     if ($method == 'DELETE') {
         $rawData = null;
     }
     // Set an If-Match header if:
     //   - This isn't a DELETE
     //   - If this isn't a GET, the Etag isn't weak
     //   - A similar header (If-Match/If-None-Match) hasn't already been
     //     set.
     if ($method != 'DELETE' && (!array_key_exists('If-Match', $headers) && !array_key_exists('If-None-Match', $headers))) {
         $allowWeak = $method == 'GET';
         if ($ifMatchHeader = $this->generateIfMatchHeaderData($data, $allowWeak)) {
             $headers['If-Match'] = $ifMatchHeader;
         }
     }
     if ($method != 'POST' && $method != 'GET' && Zend_Gdata_App::getHttpMethodOverride()) {
         $headers['x-http-method-override'] = $method;
         $method = 'POST';
     } else {
         $headers['x-http-method-override'] = null;
     }
     if ($contentTypeOverride != null) {
         $finalContentType = $contentTypeOverride;
     }
     return array('method' => $method, 'url' => $url, 'data' => $rawData, 'headers' => $headers, 'contentType' => $finalContentType);
 }
开发者ID:bizanto,项目名称:Hooked,代码行数:96,代码来源:App.php

示例2: testSetAndGetHttpMethodOverride

 public function testSetAndGetHttpMethodOverride()
 {
     Zend_Gdata_App::setHttpMethodOverride(true);
     $this->assertEquals(true, Zend_Gdata_App::getHttpMethodOverride());
 }
开发者ID:JeancarloPerez,项目名称:booking-system,代码行数:5,代码来源:AppTest.php

示例3: prepareRequest

 /**
  * Provides pre-processing for HTTP requests to APP services.  
  *
  * 1. Checks the $data element and, if it's an entry, extracts the XML, 
  *    multipart data, edit link (PUT,DELETE), etc.
  * 2. If $data is a string, sets the default content-type  header as 
  *    'application/atom+xml' if it's not already been set.
  * 3. Adds a x-http-method override header and changes the HTTP method 
  *    to 'POST' if necessary as per getHttpMethodOverride()
  *
  * @param string $method The HTTP method for the request - 'GET', 'POST', 
  *                       'PUT', 'DELETE'
  * @param string $url The URL to which this request is being performed, 
  *                    or null if found in $data
  * @param array $headers An associative array of HTTP headers for this 
  *                       request
  * @param mixed $data The Zend_Gdata_App_Entry or XML for the  
  *                    body of the request
  * @param string $contentTypeOverride The override value for the 
  *                                    content type of the request body
  * @return array An associative array containing the determined 
  *               'method', 'url', 'data', 'headers', 'contentType'
  */
 public function prepareRequest($method, $url = null, $headers = array(), $data = null, $contentTypeOverride = null)
 {
     $rawData = null;
     $finalContentType = null;
     if ($url == null) {
         $url = $this->_defaultPostUri;
     }
     if (is_string($data)) {
         $rawData = $data;
         if ($contentTypeOverride === null) {
             $finalContentType = 'application/atom+xml';
         }
     } elseif ($data instanceof Zend_Gdata_App_MediaEntry) {
         $rawData = $data->encode();
         if ($data->getMediaSource() !== null) {
             $finalContentType = 'multipart/related; boundary="' . $data->getBoundary() . '"';
             $headers['MIME-version'] = '1.0';
             $headers['Slug'] = $data->getMediaSource()->getSlug();
         } else {
             $finalContentType = 'application/atom+xml';
         }
         if ($method == 'PUT' || $method == 'DELETE') {
             $editLink = $data->getEditLink();
             if ($editLink != null) {
                 $url = $editLink->getHref();
             }
         }
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $rawData = $data->saveXML();
         $finalContentType = 'application/atom+xml';
         if ($method == 'PUT' || $method == 'DELETE') {
             $editLink = $data->getEditLink();
             if ($editLink != null) {
                 $url = $editLink->getHref();
             }
         }
     } elseif ($data instanceof Zend_Gdata_App_MediaSource) {
         $rawData = $data->encode();
         if ($data->getSlug() !== null) {
             $headers['Slug'] = $data->getSlug();
         }
         $finalContentType = $data->getContentType();
     }
     if ($method == 'DELETE') {
         $rawData = null;
     }
     if ($method != 'POST' && $method != 'GET' && Zend_Gdata_App::getHttpMethodOverride()) {
         $headers['x-http-method-override'] = $method;
         $method = 'POST';
     } else {
         $headers['x-http-method-override'] = null;
     }
     if ($contentTypeOverride != null) {
         $finalContentType = $contentTypeOverride;
     }
     return array('method' => $method, 'url' => $url, 'data' => $rawData, 'headers' => $headers, 'contentType' => $finalContentType);
 }
开发者ID:janssit,项目名称:www.alu-andries.be,代码行数:80,代码来源:App.php

示例4: delete

 /**
  * DELETE entry with client object
  *
  * @param mixed $data The Zend_Gdata_App_Entry or URL to delete
  * @return void
  * @throws Zend_Gdata_App_Exception
  * @throws Zend_Gdata_App_HttpException
  * @throws Zend_Gdata_App_InvalidArgumentException
  */
 public function delete($data, $remainingRedirects = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if (is_string($data)) {
         $uri = $data;
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $editLink = $data->getEditLink();
         if ($editLink != null) {
             $uri = $editLink->getHref();
         }
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a string or a child of Zend_Gdata_App_Entry');
     }
     if ($uri === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
     }
     $this->_httpClient->resetParameters();
     $this->_httpClient->setHeaders('x-http-method-override', null);
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     try {
         if (Zend_Gdata_App::getHttpMethodOverride()) {
             $this->_httpClient->setHeaders(array('X-HTTP-Method-Override: DELETE'));
             $this->_httpClient->setRawData('');
             $response = $this->_httpClient->request('POST');
         } else {
             $response = $this->_httpClient->request('DELETE');
         }
     } catch (Zend_Http_Client_Exception $e) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     if ($response->isRedirect()) {
         if ($remainingRedirects > 0) {
             $newUri = $response->getHeader('Location');
             $response = $this->delete($newUri, $remainingRedirects - 1);
         } else {
             require_once 'Zend/Gdata/App/HttpException.php';
             throw new Zend_Gdata_App_HttpException('No more redirects allowed', null, $response);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
开发者ID:dalinhuang,项目名称:popo,代码行数:63,代码来源:App.php

示例5: delete

 /**
  * Deletes this entry to the server using the referenced 
  * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this 
  * entry's link collection.  
  *
  * @return boolean The success of the delete operation
  * @throws Zend_Gdata_App_Exception
  */
 public function delete()
 {
     if ($this->id) {
         // If id is set, look for link rel="edit" in the
         // entry object and DELETE.
         $editLink = $this->getLink('edit');
         $editUri = $editLink->href;
         if (!$editUri) {
             throw new Zend_Gdata_App_Exception('Cannot delete entry; no link rel="edit" is present.');
         }
         $client = $this->getHttpClient();
         if (is_null($client)) {
             $client = Zend_Gdata_App::getStaticHttpClient();
         }
         $client->resetParameters();
         $client->setUri($editUri);
         $client->setHeaders('Content-Type', null);
         $client->setRawData('');
         if (Zend_Gdata_App::getHttpMethodOverride()) {
             $client->setHeaders('X-HTTP-Method-Override', 'DELETE');
             $response = $client->request('DELETE');
         } else {
             $response = $client->request('DELETE');
         }
         if ($response->getStatus() !== 200) {
             require_once 'Zend/Gdata/App/HttpException.php';
             $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
             $exception->setResponse($response);
             throw $exception;
         }
         return true;
     } else {
         throw new Zend_Gdata_App_Exception('Cannot edit entry; no id is present');
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:43,代码来源:Entry.php


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