/** * 供插件管理器主动加载的入口 */ public function __construct() { //你想自动挂接的钩子列表 \Norma\Hook::register('hello', array(&$this, 'sayHello')); \Norma\Hook::register('bye', 'Norma\\Plugin\\Demo::sayBye'); \Norma\Hook::register('hi', 'Norma\\Plugin\\Demo::sayHi', array('demo')); }
public function __construct() { \Norma\Hook::set('request_action', array(&$this, 'run')); }
public function __construct() { \Norma\Hook::register('demo_app_plugin', array(&$this, 'demo_app_plugin')); }
function build($appid) { $project_path = (\Norma\Config::get('build.project_path') ?: dirname(dirname(FRAME_PATH)) . '/project') . '/' . $appid; \Norma\Hook::trigger('build_app', array('project_path' => $project_path, 'buildoption' => ['__dir__' => ['Runtime/cache', 'Runtime/log', 'Runtime/temp', 'Runtime/template', 'Config'], 'demo' => ['__file__' => ['common.php'], '__dir__' => ['behavior', 'controller', 'model', 'view'], 'controller' => ['Index', 'Test', 'UserType'], 'model' => ['User', 'UserType'], 'view' => ['index/index']]])); return $this->fetch(); }
public function __construct() { \Norma\Hook::register('build_app', array(&$this, 'build_app')); }
// | Author: LunnLew <*****@*****.**> // +---------------------------------------------------------------------- // 加载函数库 require FRAME_PATH . '/functions.php'; // 注册框架类加载器 require FRAME_PATH . '/Support/Traits/LoaderHelper.php'; require __DIR__ . '/Loader.php'; // 注册类加载器 $loader = new \Norma\Loader(); $loader->register(); $loader->addNamespace('Norma', FRAME_PATH); \Norma\App::$loader = $loader; // 注册错误和异常处理机制 \Norma\Error::register(); // 加载Composer库 defined('COMPOSER_VENDOR_PATH') and (require_once COMPOSER_VENDOR_PATH . '/autoload.php'); // 加载默认全局配置文件 \Norma\Config::load(FRAME_PATH . '/Config/Global-default.php'); // 加载应用配置文件 \Norma\Config::load(APP_PATH . '/Config/Global.php'); // 平台兼容支持 \Norma\Constant::LoadDefineWith([\Norma\Support\Evn::DetectOS(), function () { \Norma\Support\Evn::DetectEngine(); if (!empty(\Norma\Support\Evn::$runEngineEx)) { \Norma\Constant::LoadDefineWith(\Norma\Support\Evn::$runEngineEx, FRAME_PATH . '/Compatibility'); } return \Norma\Support\Evn::$runEngine; }, \Norma\Support\Evn::DetectAccessMode()], FRAME_PATH . '/Compatibility'); // 加载插件 \Norma\Hook::loadPlugin(FRAME_PATH . '/Plugin');
/** * 供插件管理器主动加载的入口 */ public function __construct() { \Norma\Hook::set('output', array(&$this, 'output')); }
public function deafultAppInitialize() { \Norma\Support\Evn::isWeb() && \Norma\Hook::loadPlugin(APP_LIB_PATH . '/Plugin', ''); }
/** * 解析规则路由 * @access private * @param string $rule 路由规则 * @param string $route 路由地址 * @param string $pathinfo URL地址 * @param array $option 路由参数 * @param array $matches 匹配的变量 * @param bool $merge 合并额外变量 * @return array */ private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [], $merge = false) { // 检测是否定义路由 if (!empty($option['after_behavior'])) { if ($option['after_behavior'] instanceof \Closure) { $result = call_user_func_array($option['after_behavior'], [$route]); } else { foreach ((array) $option['after_behavior'] as $behavior) { $result = Hook::exec($behavior, '', $route); if (!is_null($result)) { break; } } } // 路由规则重定向 if ($result instanceof Response) { return ['type' => 'response', 'response' => $result, 'params' => $matches]; } elseif (is_array($result)) { return $result; } } // 解析路由规则 if ($rule) { $rule = explode('/', $rule); // 获取URL地址中的参数 $paths = $merge ? explode('/', $pathinfo, count($rule)) : explode('/', $pathinfo); foreach ($rule as $item) { $fun = ''; if (0 === strpos($item, '[:')) { $item = substr($item, 1, -1); } if (0 === strpos($item, ':')) { $var = substr($item, 1); $matches[$var] = array_shift($paths); } else { // 过滤URL中的静态变量 array_shift($paths); } } } else { $paths = explode('/', $pathinfo); } // 获取路由地址规则 $url = $route; // 替换路由地址中的变量 if (is_string($url) && !empty($matches)) { foreach ($matches as $key => $val) { if (false !== strpos($url, ':' . $key)) { $url = str_replace(':' . $key, $val, $url); unset($matches[$key]); } } } if ($url instanceof \Closure) { // 执行闭包 $result = ['type' => 'function', 'function' => $url, 'params' => $matches]; } elseif (0 === strpos($url, '/') || 0 === strpos($url, 'http')) { // 路由到重定向地址 $result = ['type' => 'redirect', 'url' => $url, 'status' => isset($option['status']) ? $option['status'] : 301]; } elseif (0 === strpos($url, '\\')) { // 路由到方法 $method = strpos($url, '@') ? explode('@', $url) : $url; $result = ['type' => 'method', 'method' => $method, 'params' => $matches]; } elseif (0 === strpos($url, '@')) { // 路由到控制器 $result = ['type' => 'controller', 'controller' => substr($url, 1), 'params' => $matches]; } else { // 路由到模块/控制器/操作 $result = self::parseModule($url); } // 解析额外参数 self::parseUrlParams(empty($paths) ? '' : implode('/', $paths), $matches); // 记录匹配的路由信息 Request::instance()->routeInfo(['rule' => $rule, 'route' => $route, 'option' => $option]); return $result; }
/** * 初始化应用或模块 * @access public * @param string $module 模块名 * @return array */ private static function init($module = '') { // 定位模块目录 $module = $module ? $module . DIRECTORY_SEPARATOR : ''; // 加载初始化文件 if (is_file(APP_PATH . '/' . $module . 'init' . '.php')) { include APP_PATH . '/' . $module . 'init' . '.php'; } else { $path = APP_PATH . '/' . $module; // 加载模块配置 $config = Config::load(APP_PATH . '/Config/' . $module . 'config' . '.php'); // 加载应用状态配置 if ($config['app_status']) { $config = Config::load(APP_PATH . '/Config/' . $module . $config['app_status'] . '.php'); } // 读取扩展配置文件 if ($config['extra_config_list']) { foreach ($config['extra_config_list'] as $name => $file) { $filename = APP_PATH . '/Config/' . $module . $file . '.php'; Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME)); } } // 加载别名文件 if (is_file(APP_PATH . '/Config/' . $module . 'alias' . '.php')) { Loader::addClassMap(include APP_PATH . '/Config/' . $module . 'alias' . '.php'); } // 加载行为扩展文件 if (is_file(APP_PATH . '/Config/' . $module . 'tags' . '.php')) { Hook::import(include APP_PATH . '/Config/' . $module . 'tags' . '.php'); } // 加载公共文件 if (is_file($path . 'common' . '.php')) { include $path . 'common' . '.php'; } // 加载插件 \Norma\Hook::loadPlugin($path . '/Plugin', ($config['app_namespace'] ?: 'App') . '\\' . trim($module, DIRECTORY_SEPARATOR)); // 加载当前模块语言包 if ($config['lang_switch_on'] && $module) { Lang::load($path . 'lang' . DIRECTORY_SEPARATOR . Request::instance()->langset() . '.php'); } } return Config::get(); }