/** * Api 路由器 * * @return api()->response(); * * @author AlpFish 2016/7/24 10:55 */ public static function run() { //获取路径 $path = ab_path(self::$path); if (!file_exists($path)) { return api('data')->status(500, '服务器Api目录设置错误')->response(); } //获取method if (!request('method') && empty(self::$method)) { return api('data')->status(400, '缺少请求参数:method')->response(); } $method = self::get_real_method($path); //版本处理 $v = request('version') ? request('version') : self::$version; if (!file_exists($path .= $v . '/')) { return api('data')->status(404, 'Api版本不正确')->response(); } //路由寻址 $method = explode('.', $method); $count = count($method); for ($i = 0; $i <= $count - 3; $i++) { $path .= $method[$i] . '/'; } $controller = $method[$count - 2] . self::$suffix; $action = $method[$count - 1]; if (is_file($file = $path . strtolower($controller . self::$suffix . '.php'))) { require_once $file; if (class_exists($controller) && method_exists($controller, $action)) { $class = new $controller(); return $class->{$action}(); } } return api('data')->status(404, '错误的 api 名称:' . request('method'))->response(); }
/** * 搜索加载单独配置文件 * * @param string $key * * @return $this */ private function seachLoad($key) { $name = explode('.', $key); $configFiles = [ab_path('/vendor/alpfish/me/config/' . $name[0] . '.php'), ab_path('/config/' . $name[0] . '.php')]; foreach ($configFiles as $file) { if (is_file($file)) { $config[$name[0]] = (array) (require_once $file); self::$data = array_merge(self::$data, $config); } } }
<?php namespace Me\Http; require_once ab_path() . '/vendor/mobiledetect/mobiledetectlib/Mobile_Detect.php'; class Mobile extends \Mobile_Detect { public static $self; public static function getInstance() { if (self::$self) { return self::$self; } return self::$self = new self(); } }