public function __construct($config, ServiceManager $serviceManager) { $this->config = $config; $this->serviceManager = $serviceManager; $this->request = $serviceManager->get('Request'); $this->response = $serviceManager->get('Response'); $this->server = new \Zend\XmlRpc\Server(); $this->server->setReturnResponse(true); if (array_key_exists('service', $config) && is_array($config['service']) && !empty($config['service'])) { foreach ($config['service'] as $k => $v) { try { $this->server->setClass($k, $v); //$this->server->setClass('App\XmlRpc\Service\Cargoitem', 'cargoitem'); } catch (\Exception $e) { print_r($e->getMessage()); die; } } } }
/** * handle() test - default behavior should be to not return the response */ public function testHandle() { $request = new Request(); $request->setMethod('system.listMethods'); $this->_server->setReturnResponse(false); ob_start(); $response = $this->_server->handle($request); $output = ob_get_contents(); ob_end_clean(); $this->_server->setReturnResponse(true); $this->assertFalse(isset($response)); $response = $this->_server->getResponse(); $this->assertTrue($response instanceof Response); $this->assertSame($response->__toString(), $output); $return = $response->getReturnValue(); $this->assertTrue(is_array($return)); $this->assertTrue(in_array('system.multicall', $return)); }
<?php use Zend\XmlRpc\Server; require_once __DIR__ . '/../../vendor/autoload.php'; class Foo { public function bar() { return 'bar remote!'; } } $server = new Server(); $server->setClass(new Foo(), 'Foo'); $server->setReturnResponse(false); $server->handle();