Microsoft_Http
[ class tree: Microsoft_Http ] [ index: Microsoft_Http ] [ all elements ]

Source for file Transport.php

Documentation is available at Transport.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2009, RealDolmen
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *     * Redistributions of source code must retain the above copyright
  9.  *       notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above copyright
  11.  *       notice, this list of conditions and the following disclaimer in the
  12.  *       documentation and/or other materials provided with the distribution.
  13.  *     * Neither the name of RealDolmen nor the
  14.  *       names of its contributors may be used to endorse or promote products
  15.  *       derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Microsoft
  29.  * @package    Microsoft_Http
  30.  * @subpackage Transport
  31.  * @version    $Id: Transport.php 21617 2009-06-12 10:46:31Z unknown $
  32.  * @copyright  Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  33.  * @license    http://phpazure.codeplex.com/license
  34.  */
  35.  
  36. /**
  37.  * @see Microsoft_Http_Exception
  38.  */
  39. require_once 'Microsoft/Http/Exception.php';
  40.  
  41. /**
  42.  * @see Microsoft_Http_Response
  43.  */
  44. require_once 'Microsoft/Http/Response.php';
  45.  
  46. /**
  47.  * @see Microsoft_Http_Transport_Curl
  48.  */
  49. require_once 'Microsoft/Http/Transport/Curl.php';
  50.  
  51. /**
  52.  * @category   Microsoft
  53.  * @package    Microsoft_Http
  54.  * @subpackage Transport
  55.  * @copyright  Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  56.  * @license    http://phpazure.codeplex.com/license
  57.  */
  58. abstract class Microsoft_Http_Transport
  59. {
  60.     /** HTTP VERBS */
  61.     const VERB_GET      'GET';
  62.     const VERB_PUT      'PUT';
  63.     const VERB_POST     'POST';
  64.     const VERB_DELETE   'DELETE';
  65.     const VERB_HEAD     'HEAD';
  66.     const VERB_MERGE    'MERGE';
  67.     
  68.     /**
  69.      * Use proxy?
  70.      * 
  71.      * @var boolean 
  72.      */
  73.     protected $_useProxy = false;
  74.     
  75.     /**
  76.      * Proxy url
  77.      * 
  78.      * @var string 
  79.      */
  80.     protected $_proxyUrl = '';
  81.     
  82.     /**
  83.      * Proxy port
  84.      * 
  85.      * @var int 
  86.      */
  87.     protected $_proxyPort = 80;
  88.     
  89.     /**
  90.      * Proxy credentials
  91.      * 
  92.      * @var string 
  93.      */
  94.     protected $_proxyCredentials = '';
  95.     
  96.     /**
  97.      * Set proxy
  98.      * 
  99.      * @param boolean $useProxy         Use proxy?
  100.      * @param string  $proxyUrl         Proxy URL
  101.      * @param int     $proxyPort        Proxy port
  102.      * @param string  $proxyCredentials Proxy credentials
  103.      */
  104.     public function setProxy($useProxy false$proxyUrl ''$proxyPort 80$proxyCredentials '')
  105.     {
  106.         $this->_useProxy = $useProxy;
  107.         $this->_proxyUrl = $proxyUrl;
  108.         $this->_proxyPort = $proxyPort;
  109.         $this->_proxyCredentials = $proxyCredentials;
  110.     }
  111.     
  112.     /**
  113.      * User agent string
  114.      * 
  115.      * @var string 
  116.      */
  117.     protected $_userAgent = 'Microsoft_Http_Transport';
  118.     
  119.     /**
  120.      * Perform GET request
  121.      * 
  122.      * @param $url              Url to request
  123.      * @param $variables        Array of key-value pairs to use in the request
  124.      * @param $headers          Array of key-value pairs to use as additional headers
  125.      * @param $rawBody          Raw body to send to server
  126.      * @return Microsoft_Http_Response 
  127.      */
  128.     public function get($url$variables array()$headers array()$rawBody null)
  129.     {
  130.         return $this->request(self::VERB_GET$url$variables$headers$rawBody);
  131.     }
  132.     
  133.     /**
  134.      * Perform PUT request
  135.      * 
  136.      * @param $url              Url to request
  137.      * @param $variables        Array of key-value pairs to use in the request
  138.      * @param $headers          Array of key-value pairs to use as additional headers
  139.      * @param $rawBody          Raw body to send to server
  140.      * @return Microsoft_Http_Response 
  141.      */
  142.     public function put($url$variables array()$headers array()$rawBody null)
  143.     {
  144.         return $this->request(self::VERB_PUT$url$variables$headers$rawBody);
  145.     }
  146.     
  147.     /**
  148.      * Perform POST request
  149.      * 
  150.      * @param $url              Url to request
  151.      * @param $variables        Array of key-value pairs to use in the request
  152.      * @param $headers          Array of key-value pairs to use as additional headers
  153.      * @param $rawBody          Raw body to send to server
  154.      * @return Microsoft_Http_Response 
  155.      */
  156.     public function post($url$variables array()$headers array()$rawBody null)
  157.     {
  158.         return $this->request(self::VERB_POST$url$variables$headers$rawBody);
  159.     }
  160.     
  161.     /**
  162.      * Perform DELETE request
  163.      * 
  164.      * @param $url              Url to request
  165.      * @param $variables        Array of key-value pairs to use in the request
  166.      * @param $headers          Array of key-value pairs to use as additional headers
  167.      * @param $rawBody          Raw body to send to server
  168.      * @return Microsoft_Http_Response 
  169.      */
  170.     public function delete($url$variables array()$headers array()$rawBody null)
  171.     {
  172.         return $this->request(self::VERB_DELETE$url$variables$headers$rawBody);
  173.     }
  174.     
  175.     /**
  176.      * Perform request
  177.      * 
  178.      * @param $httpVerb         Http verb to use in the request
  179.      * @param $url              Url to request
  180.      * @param $variables        Array of key-value pairs to use in the request
  181.      * @param $headers          Array of key-value pairs to use as additional headers
  182.      * @param $rawBody          Raw body to send to server
  183.      * @return Microsoft_Http_Response 
  184.      */
  185.     public abstract function request($httpVerb$url$variables array()$headers array()$rawBody null);
  186.     
  187.     /**
  188.      * Create channel
  189.      * 
  190.      * @param $type string   Transport channel type
  191.      * @return Microsoft_Http_Transport 
  192.      */
  193.     public static function createChannel($type 'Microsoft_Http_Transport_Curl')
  194.     {
  195.         return new $type();
  196.     }
  197. }

Documentation generated on Thu, 26 Nov 2009 08:05:40 +0100 by phpDocumentor 1.4.3