/** * 获取回调函数对象 * * @param mixed $closure 回调函数对象 * * @return array */ public static function getClosure($closure) { if (empty($closure)) { return null; } $closureType = null; if (self::isClosure($closure)) { $closureType = 'closure'; } else { if (is_callable($closure)) { $closureType = 'callable'; } else { if (is_string($closure)) { $closure = \Ws\Helper\Arrays::normalize($closure, '@'); // class, method $class = array_shift($closure); if (class_exists($class)) { $method = array_shift($closure); if (empty($method)) { $method = 'execute'; } if (is_callable([$class, $method])) { $closureType = 'method'; $closure = [$class, $method]; } } } } } if (empty($closureType)) { return null; } return ['type' => $closureType, 'closure' => $closure]; }
private static function _get_nested_keys($key) { $keys = \Ws\Helper\Arrays::normalize($key, '/'); $last = array_pop($keys); return [$keys, $last]; }
/** * 解析请求并挂载到指定应用 * * @param Request $request * * @return \Ws\Mvc\App */ private static function parseMointpoints(Request $request) { static $firstIs = true; $pathinfo = $request->pathinfo(); \Ws\Debug\Tracks::instance()->track('sys:init', $pathinfo); $mounts = (array) self::$config->get('app.mounts'); if ($firstIs) { // 格式化 $mounts foreach ($mounts as $appId => $options) { if (is_dir($options['dir'])) { $options['dir'] = rtrim($options['dir'], '\\/'); $options['mount'] = rtrim($options['mount'], '\\/') . '/'; $options['len'] = strlen($options['mount']); $mounts[$appId] = $options; } else { unset($mounts[$appId]); } } $mounts = Arrays::sort_by_col($mounts, 'len', SORT_DESC); self::$config->set('app.mounts', $mounts); $firstIs = false; } $app = null; // 定位挂载点 foreach ($mounts as $appId => $options) { $pa = $pathinfo; $idstr = '/^' . str_replace('/', '\\/', $options['mount']) . '/i'; // 匹配pathinfo /a => /a/ 的区别 if ($options['mount'] == "{$pa}/") { $pa = "{$pa}/"; } if (preg_match($idstr, $pa)) { $app = self::loadApp($appId, $options); if (!empty($app)) { $pathing = preg_replace($idstr, '', $pa); $app->setPathing($pathing); } break; } } return $app; }