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 / XML / RPC2 / Backend.php next >
Encoding:
PHP Script  |  2008-07-02  |  6.9 KB  |  193 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  4.  
  5. // LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ 
  6.  
  7. /**
  8. * +-----------------------------------------------------------------------------+
  9. * | Copyright (c) 2004-2006 Sergio Goncalves Carvalho                                |
  10. * +-----------------------------------------------------------------------------+
  11. * | This file is part of XML_RPC2.                                              |
  12. * |                                                                             |
  13. * | XML_RPC2 is free software; you can redistribute it and/or modify            |
  14. * | it under the terms of the GNU Lesser General Public License as published by |
  15. * | the Free Software Foundation; either version 2.1 of the License, or         |
  16. * | (at your option) any later version.                                         |
  17. * |                                                                             |
  18. * | XML_RPC2 is distributed in the hope that it will be useful,                 |
  19. * | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
  20. * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
  21. * | GNU Lesser General Public License for more details.                         |
  22. * |                                                                             |
  23. * | You should have received a copy of the GNU Lesser General Public License    |
  24. * | along with XML_RPC2; if not, write to the Free Software                     |
  25. * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                    |
  26. * | 02111-1307 USA                                                              |
  27. * +-----------------------------------------------------------------------------+
  28. * | Author: Sergio Carvalho <sergio.carvalho@portugalmail.com>                  |
  29. * +-----------------------------------------------------------------------------+
  30. *
  31. * @category   XML
  32. * @package    XML_RPC2
  33. * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  34. * @copyright  2004-2006 Sergio Carvalho
  35. * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  36. * @version    CVS: $Id: Backend.php,v 1.4 2006/01/22 01:49:35 fab Exp $
  37. * @link       http://pear.php.net/package/XML_RPC2
  38. */
  39.  
  40. // }}}
  41.  
  42. // dependencies {{{
  43. require_once 'XML/RPC2/Exception.php';
  44. // }}}
  45.  
  46. /**
  47.  * XML_RPC Backend class. The backend is responsible for the actual execution of 
  48.  * a request, as well as payload encoding and decoding. 
  49.  *
  50.  * The only external usage of this class is when explicitely setting the backend, as in
  51.  * <code>
  52.  *  XML_RPC2_Backend::setBackend('php');
  53.  *  // or
  54.  *  XML_RPC2_Backend::setBackend('xmlrpcext');
  55.  * </code>
  56.  * Note that if you do not explicitely set the backend, it will be selected automatically.
  57.  *
  58.  * Internally, this class provides methods to obtain the relevant backend classes:
  59.  *  - The server class
  60.  *  - The client class
  61.  *  - The value class
  62.  * 
  63.  * @category   XML
  64.  * @package    XML_RPC2
  65.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  66.  * @copyright  2004-2006 Sergio Carvalho
  67.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  68.  * @link       http://pear.php.net/package/XML_RPC2
  69.  */
  70. abstract class XML_RPC2_Backend 
  71. {
  72.  
  73.     // {{{ properties
  74.     
  75.     /**
  76.      * current backend
  77.      *
  78.      * @var string
  79.      */
  80.     protected static $currentBackend;
  81.     
  82.     // }}}
  83.     // {{{ setBackend()
  84.     
  85.     /**
  86.      * Backend setter. 
  87.      * 
  88.      * Currently, two backends exist: 'php' and 'XMLRPCext'. 
  89.      * The PHP backend has no external dependencies, while the xmlrpcext
  90.      * requires the xmlrpc extension. 
  91.      *
  92.      * The XMLRPCext backend is quite faster, and will be automatically 
  93.      * selected when no explicit backend has been set and the extension
  94.      * is available.
  95.      *
  96.      * @param string The backend to select. Either 'php' or 'XMLRPCext'.
  97.      */ 
  98.     public static function setBackend($backend)
  99.     {
  100.         $backend = ucfirst(strtolower($backend));
  101.         if (
  102.             $backend != 'Php' && 
  103.             $backend != 'Xmlrpcext'
  104.            ) {
  105.             throw new XML_RPC2_Exception(sprintf('Backend %s does not exist', $backend));
  106.         }       
  107.         if (
  108.             $backend == 'Xmlrpcext' &&
  109.             !function_exists('xmlrpc_server_create') &&
  110.             !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely)
  111.               @dl('php_xmlrpc' . PHP_SHLIB_SUFFIX)    || @dl('xmlrpc' . PHP_SHLIB_SUFFIX)
  112.              )
  113.            ) {
  114.             throw new XML_RPC2_Exception('Unable to load xmlrpc extension.');
  115.         }     
  116.         self::$currentBackend = $backend;
  117.     }
  118.     
  119.     // }}}
  120.     // {{{ getBackend()
  121.     
  122.     /**
  123.      * Backend getter. 
  124.      * 
  125.      * Return the current backend name. If no backend was previously selected
  126.      * select one and set it.
  127.      *
  128.      * The xmlrpcext backend is preferred, and will be automatically 
  129.      * selected when no explicit backend has been set and the xmlrpc
  130.      * extension exists. If it does not exist, then the php backend is 
  131.      * selected.
  132.      *
  133.      * @return string The current backend
  134.      */ 
  135.     protected static function getBackend()
  136.     {
  137.         if (!isset(self::$currentBackend)) {
  138.             try {
  139.                 self::setBackend('XMLRPCext'); // We prefer this one
  140.             } catch (XML_RPC2_Exception $e) {
  141.                 // TODO According to PEAR CG logging should occur here
  142.                 self::setBackend('php');     // But will settle with this one in case of error
  143.             }
  144.         }
  145.         return self::$currentBackend;
  146.     }
  147.     
  148.     // }}}
  149.     // {{{ getServerClassname()
  150.     
  151.     /**
  152.      * Include the relevant php files for the server class, and return the backend server
  153.      * class name.
  154.      *
  155.      * @return string The Server class name
  156.      */
  157.     public static function getServerClassname() {
  158.         require_once(sprintf('XML/RPC2/Backend/%s/Server.php', self::getBackend()));
  159.         return sprintf('XML_RPC2_Backend_%s_Server', self::getBackend());
  160.     }
  161.     
  162.     // }}}
  163.     // {{{ getClientClassname()
  164.     
  165.     /**
  166.      * Include the relevant php files for the client class, and return the backend client
  167.      * class name.
  168.      *
  169.      * @return string The Client class name
  170.      */
  171.     public static function getClientClassname() {
  172.         require_once(sprintf('XML/RPC2/Backend/%s/Client.php', self::getBackend()));
  173.         return sprintf('XML_RPC2_Backend_%s_Client', self::getBackend());
  174.     }
  175.     
  176.     // }}}
  177.     // {{{ getValueClassname()
  178.         
  179.     /**
  180.      * Include the relevant php files for the value class, and return the backend value
  181.      * class name.
  182.      *
  183.      * @return string The Value class name
  184.      */
  185.     public static function getValueClassname() {
  186.         require_once(sprintf('XML/RPC2/Backend/%s/Value.php', self::getBackend()));
  187.         return sprintf('XML_RPC2_Backend_%s_Value', self::getBackend());
  188.     }
  189.     
  190.     // }}}
  191.     
  192. }
  193.