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


PHP Zend_Feed::getHttpMethodOverride方法代码示例

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


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

示例1: save

 /**
  * Save a new or updated Atom entry.
  *
  * Save is used to either create new entries or to save changes to
  * existing ones. If we have a link rel="edit", we are changing
  * an existing entry. In this case we re-serialize the entry and
  * PUT it to the edit URI, checking for a 200 OK result.
  *
  * For posting new entries, you must specify the $postUri
  * parameter to save() to tell the object where to post itself.
  * We use $postUri and POST the serialized entry there, checking
  * for a 201 Created response. If the insert is successful, we
  * then parse the response from the POST to get any values that
  * the server has generated: an id, an updated time, and its new
  * link rel="edit".
  *
  * @param  string $postUri Location to POST for creating new entries.
  * @return void
  * @throws Zend_Feed_Exception
  */
 public function save($postUri = null)
 {
     if ($this->id()) {
         // If id is set, look for link rel="edit" in the
         // entry object and PUT.
         $editUri = $this->link('edit');
         if (!$editUri) {
             /**
              * @see Zend_Feed_Exception
              */
             require_once 'Zend/Feed/Exception.php';
             throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
         }
         $client = Zend_Feed::getHttpClient();
         $client->setUri($editUri);
         if (Zend_Feed::getHttpMethodOverride()) {
             $client->setHeaders(array('X-HTTP-Method-Override: PUT', 'Content-Type: ' . self::CONTENT_TYPE));
             $client->setRawData($this->saveXML());
             $response = $client->request('POST');
         } else {
             $client->setHeaders('Content-Type', self::CONTENT_TYPE);
             $client->setRawData($this->saveXML());
             $response = $client->request('PUT');
         }
         if ($response->getStatus() !== 200) {
             /**
              * @see Zend_Feed_Exception
              */
             require_once 'Zend/Feed/Exception.php';
             throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
         }
     } else {
         if ($postUri === null) {
             /**
              * @see Zend_Feed_Exception
              */
             require_once 'Zend/Feed/Exception.php';
             throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
         }
         $client = Zend_Feed::getHttpClient();
         $client->setUri($postUri);
         $client->setHeaders('Content-Type', self::CONTENT_TYPE);
         $client->setRawData($this->saveXML());
         $response = $client->request('POST');
         if ($response->getStatus() !== 201) {
             /**
              * @see Zend_Feed_Exception
              */
             require_once 'Zend/Feed/Exception.php';
             throw new Zend_Feed_Exception('Expected response code 201, got ' . $response->getStatus());
         }
     }
     // Update internal properties using $client->responseBody;
     @ini_set('track_errors', 1);
     $newEntry = new DOMDocument();
     $status = @$newEntry->loadXML($response->getBody());
     @ini_restore('track_errors');
     if (!$status) {
         // prevent the class to generate an undefined variable notice (ZF-2590)
         if (!isset($php_errormsg)) {
             if (function_exists('xdebug_is_enabled')) {
                 $php_errormsg = '(error message not available, when XDebug is running)';
             } else {
                 $php_errormsg = '(error message not available)';
             }
         }
         /**
          * @see Zend_Feed_Exception
          */
         require_once 'Zend/Feed/Exception.php';
         throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
     }
     $newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
     if (!$newEntry) {
         /**
          * @see Zend_Feed_Exception
          */
         require_once 'Zend/Feed/Exception.php';
         throw new Zend_Feed_Exception('No root <feed> element found in server response:' . "\n\n" . $client->responseBody);
     }
//.........这里部分代码省略.........
开发者ID:fredcido,项目名称:simuweb,代码行数:101,代码来源:Atom.php

示例2: save

 /**
  * Save a new or updated Atom entry.
  *
  * Save is used to either create new entries or to save changes to
  * existing ones. If we have a link rel="edit", we are changing
  * an existing entry. In this case we re-serialize the entry and
  * PUT it to the edit URI, checking for a 200 OK result.
  *
  * For posting new entries, you must specify the $postUri
  * parameter to save() to tell the object where to post itself.
  * We use $postUri and POST the serialized entry there, checking
  * for a 201 Created response. If the insert is successful, we
  * then parse the response from the POST to get any values that
  * the server has generated: an id, an updated time, and its new
  * link rel="edit".
  *
  * @param  string $postUri Location to POST for creating new entries.
  * @throws Zend_Feed_Exception
  * @return void
  */
 public function save($postUri = null)
 {
     if ($this->id()) {
         // If id is set, look for link rel="edit" in the
         // entry object and PUT.
         $editUri = $this->link('edit');
         if (!$editUri) {
             throw new Zend_Feed_Exception('Cannot edit entry; no link rel="edit" is present.');
         }
         $client = Zend_Feed::getHttpClient();
         $client->setUri($editUri);
         if (Zend_Feed::getHttpMethodOverride()) {
             $client->setHeaders(array('X-HTTP-Method-Override: PUT', 'Content-Type: application/atom+xml'));
             $client->setRawData($this->saveXML());
             $response = $client->request('POST');
         } else {
             $client->setHeaders('Content-Type', 'application/atom+xml');
             $client->setRawData($this->saveXML());
             $response = $client->request('PUT');
         }
         if ($response->getStatus() !== 200) {
             throw new Zend_Feed_Exception('Expected response code 200, got ' . $response->getStatus());
         }
     } else {
         if ($postUri === null) {
             throw new Zend_Feed_Exception('PostURI must be specified to save new entries.');
         }
         $client = Zend_Feed::getHttpClient();
         $client->setUri($postUri);
         $client->setRawData($this->saveXML());
         $response = $client->request('POST');
         if ($response->getStatus() !== 201) {
             throw new Zend_Feed_Exception('Expected response code 201, got ' . $response->getStatus());
         }
     }
     // Update internal properties using $client->responseBody;
     @ini_set('track_errors', 1);
     $newEntry = @DOMDocument::loadXML($response->getBody());
     @ini_restore('track_errors');
     if (!$newEntry) {
         throw new Zend_Feed_Exception('XML cannot be parsed: ' . $php_errormsg);
     }
     $newEntry = $newEntry->getElementsByTagName($this->_rootElement)->item(0);
     if (!$newEntry) {
         throw new Zend_Feed_Exception('No root <feed> element found in server response:' . "\n\n" . $client->responseBody);
     }
     if ($this->_element->parentNode) {
         $oldElement = $this->_element;
         $this->_element = $oldElement->ownerDocument->importNode($newEntry, true);
         $oldElement->parentNode->replaceChild($this->_element, $oldElement);
     } else {
         $this->_element = $newEntry;
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:74,代码来源:Atom.php


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