home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Services / DynDNS / Request / common.php next >
Encoding:
PHP Script  |  2008-07-02  |  5.2 KB  |  196 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Contains the Services_DynDNS_Request_common class
  7.  * 
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  * 
  16.  * @category   Web Services
  17.  * @package    Services_DynDNS
  18.  * @author     Bryan Dunlap <bdunlap@bryandunlap.com>
  19.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  20.  * @version    CVS: $Id: common.php,v 1.1 2005/08/13 14:25:34 bdunlap Exp $
  21.  */
  22.  
  23. // {{{ Services_DynDNS_Response_common
  24.  
  25. /**
  26.  * An abstract class which provides common functionality for all current types
  27.  * of DynDNS REST API requests
  28.  * 
  29.  * @category   Web Services
  30.  * @package    Services_DynDNS
  31.  * @author     Bryan Dunlap <bdunlap@bryandunlap.com>
  32.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  33.  * @version    Release: 0.3.1
  34.  */
  35. class Services_DynDNS_Request_common
  36. {
  37.     
  38.     // {{{ properties
  39.     
  40.     /**
  41.      * The hostname of the DynDNS web service
  42.      *
  43.      * @var    string
  44.      * @access protected
  45.      */
  46.     var $host;
  47.  
  48.     /**
  49.      * The path to the DynDNS web service
  50.      *
  51.      * @var    string
  52.      * @access protected
  53.      */
  54.     var $service;
  55.  
  56.     /**
  57.      * The DynDNS system to use for requests
  58.      *
  59.      * @var    string
  60.      * @access protected
  61.      */
  62.     var $system;
  63.  
  64.     /**
  65.      * Parameters for the request
  66.      *
  67.      * @var    array
  68.      * @access protected
  69.      */
  70.     var $parameters = array();
  71.     
  72.     // }}}
  73.     // {{{ build()
  74.     
  75.     /**
  76.      * Build and return an HTTP_Request object reflecting the specifics of this
  77.      * particular DynDNS_Request
  78.      *
  79.      * @return object
  80.      * @access public
  81.      */
  82.     function &build()
  83.     {
  84.         $url = 'https://' . $this->host . $this->service;
  85.         $parameters = array('user'     => $this->parameters['username'],
  86.                             'pass'     => $this->parameters['password'],
  87.                             'http'     => SERVICES_DYNDNS_DEFAULT_HTTP_VERSION,
  88.                             'method'   => SERVICES_DYNDNS_DEFAULT_REQUEST_TYPE,
  89.                             'saveBody' => true); 
  90.         $httpRequest =& new HTTP_Request($url, $parameters);
  91.         if (!($userAgent = Services_DynDNS::getUserAgent())) {
  92.             $userAgent = SERVICES_DYNDNS_DEFAULT_USER_AGENT;
  93.         }
  94.         $httpRequest->addHeader('User-Agent', $userAgent);
  95.         $httpRequest->addQueryString('system', $this->system);
  96.         foreach ($this->parameters as $name => $value) {
  97.             if ($name != 'username' && $name != 'password') {
  98.                 $httpRequest->addQueryString($name, $value);
  99.             }
  100.         }
  101.         return $httpRequest;
  102.     }
  103.     
  104.     // }}}
  105.     // {{{ addHostname()
  106.  
  107.     /**
  108.      * Appends a hostname to the end of the 'hostname' parameter string
  109.      *
  110.      * @param string $hostname        a string containing the hostname
  111.      * @return string
  112.      * @access public
  113.      */
  114.     function addHostname($hostname)
  115.     {
  116.         $seperator = $this->parameters['hostname'] ? ',' : '';
  117.         $this->parameters['hostname'] .= $seperator . $hostname;
  118.     }
  119.     
  120.     // }}}
  121.     // {{{ getParameter()
  122.  
  123.     /**
  124.      * Returns the value for a specific parameter
  125.      *
  126.      * @param string $name        a string containing the name of
  127.      *                            the parameter
  128.      * @return string
  129.      * @access public
  130.      */
  131.     function getParameter($name)
  132.     {
  133.         if (!isset($this->parameters[$name])) {
  134.             return PEAR::raiseError("Parameter '{$name}' " .
  135.                                     "doesn't exist in class " .
  136.                                     "'Services_DynDNS_Request_" .
  137.                                     "{$this->system}'");
  138.         }
  139.         return $this->parameters[$name];
  140.     }
  141.  
  142.     // }}}
  143.     // {{{ setParameter()
  144.  
  145.     /**
  146.      * Sets the value for a specific parameter
  147.      *
  148.      * @param string $name        a string containing the name of
  149.      *                            the parameter
  150.      * @param array  $value       a string containing value of 
  151.      *                            the  parameter
  152.      * @return void
  153.      * @access public
  154.      */
  155.     function setParameter($name, $value)
  156.     {
  157.         if (!isset($this->parameters[$name])) {
  158.             return PEAR::raiseError("Parameter '{$name}' " .
  159.                                     "doesn't exist in class " .
  160.                                     "'Services_DynDNS_Request_" .
  161.                                     "{$this->system}'");
  162.         }
  163.         $this->parameters[$name] = $value;
  164.     }
  165.         
  166.     // }}}
  167.     // {{{ initialize()
  168.  
  169.     /**
  170.      * Sets the default DynDNS host, service and user agent
  171.      *
  172.      * @return void
  173.      * @access protected
  174.      */
  175.     function initialize()
  176.     {
  177.         $this->host      = SERVICES_DYNDNS_DEFAULT_HOST;
  178.         $this->service   = SERVICES_DYNDNS_DEFAULT_SERVICE;
  179.     }
  180.  
  181.     // }}}
  182.     
  183. }
  184.  
  185. // }}}
  186.  
  187. /*
  188.  * Local variables:
  189.  * tab-width: 4
  190.  * c-basic-offset: 4
  191.  * c-hanging-comment-ender-p: nil
  192.  * End:
  193.  */
  194.  
  195. ?>
  196.