/** * 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) { $parts = explode('.', basename($_SERVER['SCRIPT_NAME'])); $name = $parts[0]; $wsdl = new 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 callable $function Valid PHP callback * @param string $namespace Ignored * @return Server * @throws Exception\InvalidArgumentException If function invalid or not callable. */ public function addFunction($function, $namespace = '') { if (!is_callable($function)) { throw new Exception\InvalidArgumentException(sprintf('%s expects the first argument to be callable; received %s', __METHOD__, is_object($function) ? get_class($function) : gettype($function))); } $argv = null; if (2 < func_num_args()) { $argv = func_get_args(); $argv = array_slice($argv, 2); } $class = null; if (!is_array($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', Error::ERROR_INVALID_METHOD); return $this; } } $definition = $this->_buildSignature($method, $class); $this->addMethodServiceMap($definition); return $this; }
/** * Generate the WSDL for a set of functions. * * @return Zend\Soap\Wsdl */ protected function _generateFunctions() { $methods = array(); foreach (array_unique($this->_functions) as $func) { $methods[] = $this->_reflection->reflectFunction($func); } return $this->_generateWsdl($methods); }
/** * Attach a function or callback to the server * * @param string|array|callable $function Valid PHP callback * @param string $namespace Ignored * @throws Exception\InvalidArgumentException if function invalid or not callable * @return Server */ public function addFunction($function, $namespace = '') { if (!is_string($function) && (!is_array($function) || 2 > count($function))) { throw new Exception\InvalidArgumentException('Unable to attach function; invalid'); } if (!is_callable($function)) { throw new Exception\InvalidArgumentException('Unable to attach function; does not exist'); } $argv = null; if (2 < func_num_args()) { $argv = func_get_args(); $argv = array_slice($argv, 2); } $class = null; 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', Error::ERROR_INVALID_METHOD); return $this; } } $definition = $this->_buildSignature($method, $class); $this->_addMethodServiceMap($definition); return $this; }
/** * 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|callable $function Valid callback * @param string $namespace Optional namespace prefix * @return void * @throws \Zend\XmlRpc\Exception\InvalidArgumentException */ 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::reflectFunction($func, $argv, $namespace); $this->_buildSignature($reflection); } }
/** * reflectFunction() test; test namespaces */ public function testReflectFunction2() { $reflection = Reflection::reflectFunction('ZendTest\\Server\\reflectionTestFunction', false, 'zsr'); $this->assertEquals('zsr', $reflection->getNamespace()); }
/** * 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 Server * @throws Exception\InvalidArgumentException */ 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::reflectFunction($func, $argv, $namespace); } $this->_buildDispatchTable(); return $this; }