/** * This method calls functions on the implementation class and returns the output or Fault object in case of error to client * * @return unknown */ function serve() { if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) { if (empty($_REQUEST['method'])) { echo '<pre>'; $reflect = new ReflectionClass(get_class($this->implementation)); $restWSDL = $reflect->__toString(); $restWSDL = preg_replace('/@@.*/', "", $restWSDL); echo $restWSDL; } else { $er = new SoapError(); $er->set_error('invalid_call'); $this->fault($er); } } else { $method = $_REQUEST['method']; return $this->implementation->{$method}(); } // else }
<?php $a = array(1, 3, 5, 7); $filter = create_function('$v', 'return $v > 3;'); var_dump(array_filter($a, $filter)); $filter = function ($v) { return $v > 3; }; var_dump(array_filter($a, $filter)); $newfilter = function ($i) { return function ($v) use($i) { return $v > $i; }; }; var_dump(array_filter($a, $newfilter(5))); $class = new ReflectionClass($newfilter); echo $class->__toString();
/** * 调用反射执行类的实例化 支持依赖注入 * @access public * @param string $class 类名 * @param array $vars 变量 * @return mixed */ public static function invokeClass($class, $vars = []) { $reflect = new \ReflectionClass($class); $constructor = $reflect->getConstructor(); if ($constructor) { $args = self::bindParams($constructor, $vars); } else { $args = []; } self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info'); return $reflect->newInstanceArgs($args); }