cvs: pear /Services_Webservice Webservice.php package.xml /Services_Webservice/Webservice Common.php Definition.php Exception.php ReST.php SOAP.php
/Services_Webservice/Webservice/Definition HTML.php

From: Date: Mon, 19 Sep 2005 19:49:45 +0000
Subject: cvs: pear /Services_Webservice Webservice.php package.xml /Services_Webservice/Webservice Common.php Definition.php Exception.php ReST.php SOAP.php
/Services_Webservice/Webservice/Definition HTML.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-34869@lists.php.net to get a copy of this message
jausions Mon Sep 19 15:49:45 2005 EDT Added files: /pear/Services_Webservice/Webservice Common.php ReST.php Modified files: /pear/Services_Webservice Webservice.php package.xml /pear/Services_Webservice/Webservice Definition.php Exception.php SOAP.php /pear/Services_Webservice/Webservice/Definition HTML.php Log: Added support for static web service methods, Added more checks on web service method's visibility, Services_Webservice is now abstract, Fixed minor typos in docblock comments, Added a Services_Webservice_Common for all PHP-written backends (@todo add paylod to call and decode/encode), Added a ReST backend.

http://cvs.php.net/diff.php/pear/Services_Webservice/Webservice.php?r1=1.11&r2=1.12&ty=u Index: pear/Services_Webservice/Webservice.php diff -u pear/Services_Webservice/Webservice.php:1.11 pear/Services_Webservice/Webservice.php:1.12 --- pear/Services_Webservice/Webservice.php:1.11 Mon Sep 19 12:41:32 2005 +++ pear/Services_Webservice/Webservice.php Mon Sep 19 15:49:41 2005 @@ -19,12 +19,10 @@ * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Webservice.php,v 1.11 2005/09/19 16:41:32 jausions Exp $ + * @version CVS: $Id: Webservice.php,v 1.12 2005/09/19 19:49:41 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ -// {{{ abstract class Services_Webservice - /** * PEAR::Services_Webservice * @@ -35,7 +33,7 @@ * @package Services_Webservices * @version @version@ */ -class Services_Webservice +abstract class Services_Webservice { /** * Namespace of the web service @@ -62,12 +60,20 @@ protected $_classname; /** + * Class instance used by the web service + * + * @var object + * @access protected + */ + protected $_classnameInstance = null; + + /** * Parameter for the user's web service class * * @var array * @access protected */ - protected $_initParams = array(); + protected $_initParams = null; /** * Constructor @@ -82,6 +88,7 @@ { if (is_object($class)) { $this->_classname = $class->get_class(); + $this->_classnameInstance =& $class; } elseif (is_string($class)) { $this->_classname = $class; } else { @@ -106,7 +113,6 @@ * @access public * @throws Services_Webservice_UnknownDriverException * @throws Services_Webservice_NotClassException - * @webservice.hidden */ public function &factory($driver, $class, $namespace, $options = null) { @@ -132,6 +138,15 @@ { $this->_initParams = func_get_args(); } + + /** + * Automatically handles the incoming request + * + * The result depends on how the service was called and which backend + * is used. + * @access public + */ + abstract public function handle(); } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Services_Webservice/package.xml?r1=1.10&r2=1.11&ty=u Index: pear/Services_Webservice/package.xml diff -u pear/Services_Webservice/package.xml:1.10 pear/Services_Webservice/package.xml:1.11 --- pear/Services_Webservice/package.xml:1.10 Mon Aug 29 11:15:45 2005 +++ pear/Services_Webservice/package.xml Mon Sep 19 15:49:41 2005 @@ -49,8 +49,10 @@ <dir name="/" baseinstalldir="Services"> <file role="php">Webservice.php</file> <dir name="Webservice" role="php"> - <file role="php">Exception.php</file> + <file>Exception.php</file> <file>Definition.php</file> + <file>Common.php</file> + <file>ReST.php</file> <file>SOAP.php</file> <dir name="Definition" role="php"> <file>Exception.php</file> http://cvs.php.net/diff.php/pear/Services_Webservice/Webservice/Definition.php?r1=1.19&r2=1.20&ty=u Index: pear/Services_Webservice/Webservice/Definition.php diff -u pear/Services_Webservice/Webservice/Definition.php:1.19 pear/Services_Webservice/Webservice/Definition.php:1.20 --- pear/Services_Webservice/Webservice/Definition.php:1.19 Mon Sep 19 13:30:13 2005 +++ pear/Services_Webservice/Webservice/Definition.php Mon Sep 19 15:49:44 2005 @@ -19,7 +19,7 @@ * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Definition.php,v 1.19 2005/09/19 17:30:13 jausions Exp $ + * @version CVS: $Id: Definition.php,v 1.20 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ @@ -392,6 +392,9 @@ foreach ($methods as $method) { $methodName = $method->getName(); if ($method->isPublic() + && !$method->isAbstract() + && !$method->isConstructor() + && !$method->isDestructor() && !in_array($methodName, $this->_hiddenMethods)) { try { @@ -414,6 +417,11 @@ $this->_wsdlStruct[$this->_classname]['method'][$methodName]['deprecated'] = true; } + // Static? + if (isset($docComments['static']) || $method->isStatic()) { + $this->_wsdlStruct[$this->_classname]['method'][$methodName]['static'] = true; + } + // Description $this->_wsdlStruct[$this->_classname]['method'][$methodName]['description'] = @$docComments['shortDescription']; @@ -565,15 +573,21 @@ * Checks if a given method is exposed for the web service * * @param string $methodName method name to check accessibility for + * @param boolean &$isStatic if method is exposed and is static, this + * by-reference variable will be set to TRUE. * @return boolean TRUE if exposed, FALSE otherwise * @access public * @throws Services_Webservice_Definition_NoDocCommentException * @throws Services_Webservice_Definition_Exception */ - public function isMethodExposed($methodName) + public function isMethodExposed($methodName, &$isStatic = null) { if ($this->_wsdlStruct) { - return isset($this->_wsdlStruct[$this->_classname][$methodName]); + if (isset($this->_wsdlStruct[$this->_classname][$methodName])) { + $isStatic = isset($this->_wsdlStruct[$this->_classname][$methodName]['static']); + return true; + } + return false; } if (in_array($methodName, $this->_hiddenMethods)) { @@ -586,7 +600,10 @@ } $method = $class->getMethod($methodName); - if (!$method->isPublic()) { + if (!$method->isPublic() + || $method->isAbstract() + || $method->isConstructor() + || $method->isDestructor()) { return false; } @@ -605,6 +622,8 @@ return false; } + $isStatic = $method->isStatic(); + return true; } } http://cvs.php.net/diff.php/pear/Services_Webservice/Webservice/Exception.php?r1=1.1&r2=1.2&ty=u Index: pear/Services_Webservice/Webservice/Exception.php diff -u pear/Services_Webservice/Webservice/Exception.php:1.1 pear/Services_Webservice/Webservice/Exception.php:1.2 --- pear/Services_Webservice/Webservice/Exception.php:1.1 Mon Aug 29 11:15:45 2005 +++ pear/Services_Webservice/Webservice/Exception.php Mon Sep 19 15:49:44 2005 @@ -18,7 +18,7 @@ * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Exception.php,v 1.1 2005/08/29 15:15:45 jausions Exp $ + * @version CVS: $Id: Exception.php,v 1.2 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ @@ -35,17 +35,24 @@ } /** - * Exception calls for Invalid driver + * Exception class for Invalid driver */ class Services_Webservice_UnknownDriverException extends Services_Webservice_Exception { } /** - * Exception calls for Invalid class parameter for constructor/factory + * Exception class for Invalid class parameter for constructor/factory */ class Services_Webservice_NotClassException extends Services_Webservice_Exception { } +/** + * Exception class for call on methods that are not exposed to the web service or don't exist + */ +class Services_Webservice_IllegalCallException extends Services_Webservice_Exception +{ +} + ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Services_Webservice/Webservice/SOAP.php?r1=1.3&r2=1.4&ty=u Index: pear/Services_Webservice/Webservice/SOAP.php diff -u pear/Services_Webservice/Webservice/SOAP.php:1.3 pear/Services_Webservice/Webservice/SOAP.php:1.4 --- pear/Services_Webservice/Webservice/SOAP.php:1.3 Mon Sep 19 12:46:03 2005 +++ pear/Services_Webservice/Webservice/SOAP.php Mon Sep 19 15:49:44 2005 @@ -19,7 +19,7 @@ * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: SOAP.php,v 1.3 2005/09/19 16:46:03 jausions Exp $ + * @version CVS: $Id: SOAP.php,v 1.4 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ @@ -28,8 +28,6 @@ */ require_once 'Services/Webservice.php'; -// {{{ abstract class Services_Webservice - /** * Services_Webservice implementation for SOAP backend * @@ -77,7 +75,6 @@ * Otherwise, returns an HTML information page * * @access public - * @webservice.hidden */ public function handle() { @@ -97,9 +94,9 @@ } if ($action) { require_once 'Services/Webservice/Definition.php'; - $this->_wsdlWriter = new Services_Webservice_Definition($this->_classname, $this->namespace); - $this->_wsdlWriter->protocol = $this->protocol; - echo $this->_wsdlWriter->{'to' . $action}(); + $definition = new Services_Webservice_Definition($this->_classname, $this->namespace); + $definition->protocol = $this->protocol; + echo $definition->{'to' . $action}(); } else { $this->createServer(); } http://cvs.php.net/diff.php/pear/Services_Webservice/Webservice/Definition/HTML.php?r1=1.5&r2=1.6&ty=u Index: pear/Services_Webservice/Webservice/Definition/HTML.php diff -u pear/Services_Webservice/Webservice/Definition/HTML.php:1.5 pear/Services_Webservice/Webservice/Definition/HTML.php:1.6 --- pear/Services_Webservice/Webservice/Definition/HTML.php:1.5 Sun Aug 14 23:36:08 2005 +++ pear/Services_Webservice/Webservice/Definition/HTML.php Mon Sep 19 15:49:44 2005 @@ -19,7 +19,7 @@ * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: HTML.php,v 1.5 2005/08/15 03:36:08 jausions Exp $ + * @version CVS: $Id: HTML.php,v 1.6 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ @@ -152,7 +152,7 @@ <h1>' . $classname . '</h1> <p>' . htmlspecialchars($description) . '</p> </div> -<p>The following operations are supported. For a formal definition, please review the <a href="' . $urlWSDL . '">Service Description</a>.</p> +<p>The following operations are supported. For a formal <acronym title="Simple Object Access Protocol">SOAP</acronym> definition, please review the <a href="' . $urlWSDL . '">Service Description</a>.</p> <ul>'; foreach ($wsdlStruct[$classname]['method'] as $methodName => $method) { http://cvs.php.net/co.php/pear/Services_Webservice/Webservice/Common.php?r=1.1&p=1 Index: pear/Services_Webservice/Webservice/Common.php +++ pear/Services_Webservice/Webservice/Common.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ /** * Easy Web Service creation * * PHP 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Services * @package Services_Webservice * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: Common.php,v 1.1 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ /** * Include parent class */ require_once 'Services/Webservice.php'; /** * Services_Webservice implementation for common PHP-written backend * * The PEAR::Services_Webservice class creates web services from your classes * * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @package Services_Webservices * @version @version@ * @todo Add input/output filters that will decode/encode the data from/to * a specified format (eventually nest filters) */ class Services_Webservice_Common extends Services_Webservice { /** * Handles the method call itself * * @param string $methodName the method to call with the payload * @access protected * @webservice.hidden * @throws Services_Webservice_IllegalCallException * @todo Add payload to method calls * @todo Fix the passing of parameters to the user's class constructor */ protected function _handle($methodName) { require_once 'Services/Webservice/Definition.php'; $definition = new Services_Webservice_Definition($this->_classname, $this->namespace); $definition->protocol = $this->protocol; if (!$definition->isMethodExposed($method, $static)) { require_once 'Services/Webservice/Exception.php'; throw new Services_Webservice_IllegalCallException('Unknown web service resource'); } if ($static) { echo call_user_func_array(array($this->_classname, $methodName)); } else { if (!is_object($this->_classnameInstance)) { if (!is_null($this->_initParams)) { $this->_classnameInstance = new $this->_classname($this->_initParams); } else { $this->_classnameInstance = new $this->_classname(); } } echo call_user_func_array(array(&$this->_classnameInstance, $methodName)); } } } ?> http://cvs.php.net/co.php/pear/Services_Webservice/Webservice/ReST.php?r=1.1&p=1 Index: pear/Services_Webservice/Webservice/ReST.php +++ pear/Services_Webservice/Webservice/ReST.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ /** * Easy Web Service creation * * PHP 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Services * @package Services_Webservice * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: ReST.php,v 1.1 2005/09/19 19:49:44 jausions Exp $ * @link http://pear.php.net/package/Services_Webservice */ /** * Include parent class */ require_once 'Services/Webservice/Common.php'; /** * Services_Webservice implementation for ReST backend * * The method call is done through PATH_INFO * * The PEAR::Services_Webservice class creates web services from your classes * * @author Philippe Jausions <Philippe.Jausions@11abacus.com> * @package Services_Webservices * @version @version@ */ class Services_Webservice_ReST extends Services_Webservice_Common { /** * Automatically handles the incoming request * * The result depends on how the service was called * If a method name is passed as the PATH_INFO, it is used to call it. * If the method was not exposed as a web service method, a 404 HTTP * status is returned. * Otherwise, returns an HTML information page. * * @access public * @todo Add payload to method calls * @todo Fix the passing of parameters to the user's class constructor */ public function handle() { if (isset($_SERVER['PATH_INFO'])) { $method = $_SERVER['PATH_INFO']; try { $this->_handle($method); } catch (Services_Webservice_IllegalCallException $e) { header('HTTP/1.0 404 Not Found'); } } else { header('Content-Type: text/html'); echo $definition->toHTML(); } } } ?>
« previous php.pear.cvs (#34869) next »