Example #1
0
 /**
  * Returns a string representation
  *
  * @return string String representation
  */
 public function __toString()
 {
     if ($this->reflectionSource instanceof ReflectionMethod) {
         return $this->reflectionSource->__toString();
     } else {
         return parent::__toString();
     }
 }
function reflectMethod($class, $method)
{
    $methodInfo = new ReflectionMethod($class, $method);
    echo "**********************************\n";
    echo "Reflecting on method {$class}::{$method}()\n\n";
    echo "__toString():\n";
    var_dump($methodInfo->__toString());
    echo "\nexport():\n";
    var_dump(ReflectionMethod::export($class, $method, true));
    echo "\n**********************************\n";
}
Example #3
0
 public function __toString()
 {
     return parent::__toString();
 }
Example #4
0
File: App.php Project: GDdark/cici
 /**
  * 执行模块
  * @access public
  * @param array $result 模块/控制器/操作
  * @param array $config 配置参数
  * @param bool  $convert 是否自动转换控制器和操作名
  * @return mixed
  */
 public static function module($result, $config, $convert = null)
 {
     if (is_string($result)) {
         $result = explode('/', $result);
     }
     $request = Request::instance();
     if ($config['app_multi_module']) {
         // 多模块部署
         $module = strip_tags(strtolower($result[0] ?: $config['default_module']));
         $bind = Route::getBind('module');
         $available = false;
         if ($bind) {
             // 绑定模块
             list($bindModule) = explode('/', $bind);
             if ($module == $bindModule) {
                 $available = true;
             }
         } elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) {
             $available = true;
         }
         // 模块初始化
         if ($module && $available) {
             // 初始化模块
             $request->module($module);
             $config = self::init($module);
         } else {
             throw new HttpException(404, 'module not exists:' . $module);
         }
     } else {
         // 单一模块部署
         $module = '';
         $request->module($module);
     }
     // 当前模块路径
     App::$modulePath = APP_PATH . ($module ? $module . DS : '');
     // 是否自动转换控制器和操作名
     $convert = is_bool($convert) ? $convert : $config['url_convert'];
     // 获取控制器名
     $controller = strip_tags($result[1] ?: $config['default_controller']);
     $controller = $convert ? strtolower($controller) : $controller;
     // 获取操作名
     $actionName = strip_tags($result[2] ?: $config['default_action']);
     $actionName = $convert ? strtolower($actionName) : $actionName;
     // 设置当前请求的控制器、操作
     $request->controller($controller)->action($actionName);
     // 监听module_init
     Hook::listen('module_init', $request);
     try {
         $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
         if (is_null($instance)) {
             throw new HttpException(404, 'controller not exists:' . $controller);
         }
         // 获取当前操作名
         $action = $actionName . $config['action_suffix'];
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException('illegal action name:' . $actionName);
         }
         // 执行操作方法
         $call = [$instance, $action];
         Hook::listen('action_begin', $call);
         $data = self::invokeMethod($call);
     } catch (\ReflectionException $e) {
         // 操作不存在
         if (method_exists($instance, '_empty')) {
             $method = new \ReflectionMethod($instance, '_empty');
             $data = $method->invokeArgs($instance, [$action, '']);
             self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
         } else {
             throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
         }
     }
     return $data;
 }
 public function describeMethod(ReflectionMethod $method, $long = false)
 {
     $this->write(" " . $method->name . "\t-");
     $documentation = $method->getDocComment();
     if (!$documentation) {
         $documentation = "No documentation found! Read the source!\n";
         $documentation .= $method->__toString();
     }
     $doc_lines = explode("\n", $documentation);
     foreach ($doc_lines as $line) {
         $line = preg_replace("/^\\s*[\\/\\*]+/", '', $line);
         if ($line) {
             $this->write(" {$line}\n");
             if (!$long) {
                 return;
             }
         }
     }
 }