public function testLoadFunctionsReadsMethodsFromServerDefinitionObjects() { $mockedMethod = $this->getMock('Zend_Server_Method_Definition', array(), array(), '', false, false); $mockedDefinition = $this->getMock('Zend_Server_Definition', array(), array(), '', false, false); $mockedDefinition->expects($this->once())->method('getMethods')->will($this->returnValue(array('bar' => $mockedMethod))); $this->_server->loadFunctions($mockedDefinition); }
public function testLoadFunctionsThrowsExceptionWithBadData() { $o = new stdClass(); try { $this->_server->loadFunctions($o); $this->fail('loadFunctions() should not accept objects'); } catch (Exception $e) { // success } $o = array($o); try { $this->_server->loadFunctions($o); $this->fail('loadFunctions() should not allow non-reflection objects in an array'); } catch (Exception $e) { // success } }
/** * Add dispatch table from a file * * Unserializes a stored dispatch table from $filename. Returns false if it * fails in any way, true on success. * * Useful to prevent needing to build the dispatch list on each XMLRPC * request. Sample usage: * * <code> * if (!Zend_XmlRpc_Server_Cache::get($filename, $server)) { * require_once 'Some/Service/Class.php'; * require_once 'Another/Service/Class.php'; * * // Attach Some_Service_Class with namespace 'some' * $server->attach('Some_Service_Class', 'some'); * * // Attach Another_Service_Class with namespace 'another' * $server->attach('Another_Service_Class', 'another'); * * Zend_XmlRpc_Server_Cache::save($filename, $server); * } * * $response = $server->handle(); * echo $response; * </code> * * @param string $filename * @param Zend_XmlRpc_Server $server * @return bool */ public static function get($filename, Zend_XmlRpc_Server $server) { if (!is_string($filename) || !file_exists($filename) || !is_readable($filename)) { return false; } if (false === ($dispatch = @file_get_contents($filename))) { return false; } if (false === ($dispatchArray = @unserialize($dispatch))) { return false; } $server->loadFunctions($dispatchArray); return true; }
/** * Add dispatch table from a file * * Unserializes a stored dispatch table. Returns false if it * fails in any way, true on success. * * Useful to prevent needing to build the dispatch list on each XMLRPC * request. Sample usage: * * <code> * if (!Zym_XmlRpc_Server_Cache::get($id, $coreCache, $server)) { * require_once 'Some/Service/Class.php'; * require_once 'Another/Service/Class.php'; * * // Attach Some_Service_Class with namespace 'some' * $server->setClass('Some_Service_Class', 'some'); * * // Attach Another_Service_Class with namespace 'another' * $server->setClass('Another_Service_Class', 'another'); * * Zym_XmlRpc_Server_Cache::save($id, $coreCache, $server); * } * * $response = $server->handle(); * echo $response; * </code> * * @param string $id * @param Zend_Cache_Core $coreCache * @param Zend_XmlRpc_Server $server * * @return boolean */ public static function get($id, Zend_Cache_Core $coreCache, Zend_XmlRpc_Server $server) { $dispatchArray = @unserialize($coreCache->load($id, false, true)); try { $server->loadFunctions($dispatchArray); } catch (Zend_XmlRpc_Server_Exception $e) { return false; } return true; }
/** * get/loadFunctions() test */ public function testFunctions() { try { $this->_server->addFunction(array('Zend_XmlRpc_Server_testFunction', 'Zend_XmlRpc_Server_testFunction2'), 'zsr'); } catch (Exception $e) { $this->fail('Error attaching functions: ' . $e->getMessage()); } $expected = $this->_server->listMethods(); $functions = $this->_server->getFunctions(); $server = new Zend_XmlRpc_Server(); $server->loadFunctions($functions); $actual = $server->listMethods(); $this->assertSame($expected, $actual); }
/** * Add dispatch table from a file * * Unserializes a stored dispatch table from $filename. Returns false if it * fails in any way, true on success. * * Useful to prevent needing to build the dispatch list on each XMLRPC * request. Sample usage: * * <code> * if (!Zend_XmlRpc_Server_Cache::get($id, $coreCache, $server)) { * require_once 'Some/Service/Class.php'; * require_once 'Another/Service/Class.php'; * * // Attach Some_Service_Class with namespace 'some' * $server->attach('Some_Service_Class', 'some'); * * // Attach Another_Service_Class with namespace 'another' * $server->attach('Another_Service_Class', 'another'); * * Zend_XmlRpc_Server_Cache::save($id, $coreCache, $server); * } * * $response = $server->handle(); * echo $response; * </code> * * @param string $filename * @param Zend_XmlRpc_Server $server */ public static function get($id, Zend_Cache_Core $coreCache, Zend_XmlRpc_Server $server) { $dispatchArray = @unserialize($coreCache->load($id, false, true)); $server->loadFunctions($dispatchArray); }