/** * Add a Single or Multiple Functions to the WSDL * * @param string $function Function Name * @param string $namespace Function namespace - Not Used */ public function addFunction($function, $namespace = '') { static $port; static $operation; static $binding; if (!is_array($function)) { $function = (array) $function; } $uri = $this->getUri(); if (!$this->_wsdl instanceof WSDL\WSDL) { $parts = explode('.', basename($_SERVER['SCRIPT_NAME'])); $name = $parts[0]; $wsdl = new WSDL\WSDL($name, $uri, $this->_strategy); // The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023) $wsdl->addSchemaTypeSection(); $port = $wsdl->addPortType($name . 'Port'); $binding = $wsdl->addBinding($name . 'Binding', 'tns:' . $name . 'Port'); $wsdl->addSoapBinding($binding, $this->_bindingStyle['style'], $this->_bindingStyle['transport']); $wsdl->addService($name . 'Service', $name . 'Port', 'tns:' . $name . 'Binding', $uri); } else { $wsdl = $this->_wsdl; } foreach ($function as $func) { $method = $this->_reflection->reflectFunction($func); $this->_addFunctionToWSDL($method, $wsdl, $port, $binding); } $this->_wsdl = $wsdl; }
/** * Attach a function or callback to the server * * @param string|array $function Valid PHP callback * @param string $namespace Ignored * @return Zend\Json\Server */ public function addFunction($function, $namespace = '') { if (!is_string($function) && (!is_array($function) || 2 > count($function))) { throw new Exception('Unable to attach function; invalid'); } if (!is_callable($function)) { throw new Exception('Unable to attach function; does not exist'); } $argv = null; if (2 < func_num_args()) { $argv = func_get_args(); $argv = array_slice($argv, 2); } if (is_string($function)) { $method = Reflection::reflectFunction($function, $argv, $namespace); } else { $class = array_shift($function); $action = array_shift($function); $reflection = Reflection::reflectClass($class, $argv, $namespace); $methods = $reflection->getMethods(); $found = false; foreach ($methods as $method) { if ($action == $method->getName()) { $found = true; break; } } if (!$found) { $this->fault('Method not found', -32601); return $this; } } $definition = $this->_buildSignature($method); $this->_addMethodServiceMap($definition); return $this; }
public function testReflectFunctionThrowsExceptionOnInvalidParam() { $this->setExpectedException('Zend\\Server\\Reflection\\Exception\\InvalidArgumentException', 'Invalid function'); $reflection = Reflection\Reflection::reflectFunction(false); }
/** * Attach a callback as an XMLRPC method * * Attaches a callback as an XMLRPC method, prefixing the XMLRPC method name * with $namespace, if provided. Reflection is done on the callback's * docblock to create the methodHelp for the XMLRPC method. * * Additional arguments to pass to the function at dispatch may be passed; * any arguments following the namespace will be aggregated and passed at * dispatch time. * * @param string|array $function Valid callback * @param string $namespace Optional namespace prefix * @return void * @throws Zend\XmlRpc\Server\Exception */ public function addFunction($function, $namespace = '') { if (!is_string($function) && !is_array($function)) { throw new Server\Exception\InvalidArgumentException('Unable to attach function; invalid', 611); } $argv = null; if (2 < func_num_args()) { $argv = func_get_args(); $argv = array_slice($argv, 2); } $function = (array) $function; foreach ($function as $func) { if (!is_string($func) || !function_exists($func)) { throw new Server\Exception\InvalidArgumentException('Unable to attach function; invalid', 611); } $reflection = Reflection\Reflection::reflectFunction($func, $argv, $namespace); $this->_buildSignature($reflection); } }
/** * Attach a function to the server * * Additional arguments to pass to the function at dispatch may be passed; * any arguments following the namespace will be aggregated and passed at * dispatch time. * * @param string|array $function Valid callback * @param string $namespace Optional namespace prefix * @return Zend\Amf\Server * @throws Zend\Amf\Server\Exception */ public function addFunction($function, $namespace = '') { if (!is_string($function) && !is_array($function)) { throw new Exception\InvalidArgumentException('Unable to attach function'); } $argv = null; if (2 < func_num_args()) { $argv = array_slice(func_get_args(), 2); } $function = (array) $function; foreach ($function as $func) { if (!is_string($func) || !function_exists($func)) { throw new Exception\InvalidArgumentException('Unable to attach function'); } $this->_methods[] = Reflection\Reflection::reflectFunction($func, $argv, $namespace); } $this->_buildDispatchTable(); return $this; }
/** * reflectFunction() test; test namespaces */ public function testReflectFunction2() { $reflection = Reflection\Reflection::reflectFunction('ZendTest\\Server\\reflectionTestFunction', false, 'zsr'); $this->assertEquals('zsr', $reflection->getNamespace()); }