public static function init() { if (is_null($storage)) { Import::load(CORE_PATH . 'Logs/KLogger.php'); static::$storage = KLogger::instance(LOG_PATH, KLogger::DEBUG); } return static::$storage; }
/** * 执行controller->action * * @return void */ public static function exec() { // Controller name 安全过滤 if (!preg_match('/^[A-Za-z](\\w)*$/', CONTROLLER_NAME)) { $module = false; } else { $module = Import::controller(GROUP_NAME, CONTROLLER_NAME); } // 执行空控制器 try { if (!$module) { $module = Import::controller(GROUP_NAME, 'Empty'); if (!$module) { throw new Exception("Controller不存在,\"" . CONTROLLER_NAME . "\""); } } } catch (Exception $error) { Debug::output($error); } // 获取控制器操作名 $action = ACTION_NAME; // 定义模板名称 Config::set('TEMPLATE_NAME', THEME_PATH . CONTROLLER_NAME . '/' . $action . '.html'); try { // Action name 安全过滤 if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) { throw new ReflectionException(); } // 对当前控制器的方法执行操作映射 $method = new ReflectionMethod($module, $action); // public方法 if ($method->isPublic()) { // 映射执行 $class = new ReflectionClass($module); // 前置操作 if ($class->hasMethod('_before_' . $action)) { $before = $class->getMethod('_before_' . $action); // public并执行 if ($before->isPublic()) { $before->invoke($module); } } // URL参数绑定检测 if (Config::get('URL_PARAMS_BIND') && $method->getNumberOfParameters() > 0) { switch ($_SERVER['REQUEST_METHOD']) { case 'POST': $vars = $_POST; break; case 'PUT': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_GET; } $params = $method->getParameters(); foreach ($params as $param) { $name = $param->getName(); if (isset($vars[$name])) { $args[] = $vars[$name]; } elseif ($param->isDefaultValueAvailable()) { $args[] = $param->getDefaultValue(); } else { Debug::throw_exception(L('_PARAM_ERROR_') . ':' . $name); } } $method->invokeArgs($module, $args); } else { $method->invoke($module); } // 后置操作 if ($class->hasMethod('_after_' . $action)) { $after = $class->getMethod('_after_' . $action); // public并执行 if ($after->isPublic()) { $after->invoke($module); } } } else { throw new ReflectionException(); } } catch (ReflectionException $e) { // 方法调用发生异常后 引导到__call方法处理 $method = new ReflectionMethod($module, '__call'); $method->invokeArgs($module, array($action, '')); } }
namespace Think\Library; /** * Library/RbacAuth.class.php * Smart ThinkPHP * Copyright (c) 2004-2013 Methink * * @copyright Copyright (c) Methink * @link https://github.com/minowu/extend * @package Library.RbacAuth * @since Smart ThinkPHP Extend 1.0.0 * @license Apache License (http://www.apache.org/licenses/LICENSE-2.0) */ use Think\Import; Import::load(dirname(__FILE__) . '/Auth' . EXT); /** * 配置方法 */ /* return array( 'AUTH_KEY' => 'USER_AUTH_KEY', 'AUTH_RULES' => array( // Public 1 => array( 'Home/Index/index' => true, 'Home/Account/login' => true,
/** * 过滤器方法 引用传值 * * @param string $name 过滤器名称 * @param string $content 要过滤的内容 * * @return void */ function filter($name, &$content) { $class = $name . 'Filter'; Import::load(GROUP_PATH . 'Filter/' . $class . EXT); $filter = new $class(); $content = $filter->run($content); }