devedge/xmlrpc-server

用于创建XML-RPC服务器的PHP库

0.1.1 2014-11-01 22:00 UTC

This package is auto-updated.

Last update: 2024-08-26 01:43:03 UTC


README

Latest Stable Version License Total Downloads Scrutinizer Code Quality Code Coverage SensioLabsInsight

一个提供xml-rpc服务的库

许可证

MIT风格,见LICENSE.txt

备注

目前这个库需要当前Psr DRAFT的缓存标准,这将被php-fig发布的真实标准所取代。在此期间,这个包将依赖于devedge/stubs,其中包含psr接口的副本以及该接口和psr/log的null实现。

用法

目前这个库的功能非常有限,这也意味着使用非常简单。这个包将为你提供将xmlrpc服务集成到应用程序中所需的工具。

一个简单的示例脚本,可以被任何web服务器运行:

    <?php
    // use autoloading for the composer stuff
    require_once "../vendor/autoload.php";

    
    // create the server instance
    $server = new Devedge\XmlRpc\Server();

    
    // create an instance of your service
    // a service instance should have the methods that can be called through the xmlrpc interface.  
    $service = new Example\MyService();
    
    // create an instance of Devedge\XmlRpc\Server\Handlers\SimpleHandler. This class implements the
    // handler interface and allows to register any regular object to be used for handling the requests
    // simple handler will expose all public methods that don't start with __ towards the xmlrpc interface
    // make sure you only have methods that you actually want exposed!
    // the second parameter is a "namespace", expressing that all xmlrpc calls starting with "example." 
    // will be handled by this handler. 
    $handler = new Devedge\XmlRpc\Server\Handlers\SimpleHandler($service, "example")
    
    // as Devedge\XmlRpc\Server\Handlers\SimpleHandler implements the handler interface, the handler instance
    // can be registered as a handler with the server.
    // the server allows to register more than one handler (as long as they use different "namespaces"), and 
    // if a handler carries the namespace "default" it will also be used for methods that are called through xmlrpc
    // without a namespace set
    $server->registerHandler($handler);
    
    // lets be nice and set an xml content header.
    header("Content-Type: text/xml");
    
    // the handle method takes xmlrpc methodCall xml, and executes the handling
    // whatever return value the method of service is will be serialized as an 
    // xmlrpc answer, and available as return value of handle.
    echo $server->handle(file_get_contents('php://input'));

关于Devedge\XmlRpc\Server需要了解的其他信息

  • 它有一个名为setLogger()的方法,它接受一个psr/log兼容的日志记录器作为参数,然后会导致服务器将各种信息记录到该记录器。
  • 它有一个名为exceptionOnError的布尔成员(默认为false)。如果设置为true,处理器/服务中抛出的异常将不会转换为xmlrpc故障。在这种情况下,handle()方法将重新抛出最初抛出的异常

关于Devedge\XmlRpc\Server\Handlers\SimpleHandler需要了解的其他信息

  • SimpleHandler就像其名称一样,是一个非常简单的处理器。例如,它不会检查调用方法的签名。如果发送了对特定方法的请求,它将尝试使用所有接收到的参数调用该方法。

您可以通过编写自己的处理器(只要您实现了HandlerInterface)来轻松扩展功能(签名检查、缓存等)。

链接