/** * 加载api类 * @param array $routes * @param string $class_file * @param string $class_name * @param string $method * @return void */ private function loadApi(&$routes, $class_file, $class_name, $method = null) { Verify::isTrue(is_file($class_file), $class_file . ' is not an exist file'); Logger::debug("attempt to load api: {$class_name}, {$class_file}"); $this->class_loader->addClass($class_name, $class_file); $api = null; if ($this->ignore_load_error) { try { $api = $this->factory->create('phprs\\Container', array($class_name, $method), null, null); } catch (\Exception $e) { Logger::warning("load api: {$class_name}, {$class_file} failed with " . $e->getMessage()); return; } } else { $api = $this->factory->create('phprs\\Container', array($class_name, $method), null, null); } foreach ($api->routes as $http_method => $route) { if (!isset($routes[$http_method])) { $routes[$http_method] = new HttpRouterEntries(); } $cur = $routes[$http_method]; foreach ($route as $entry) { list($uri, $invoke, $strict) = $entry; $realpath = preg_replace('/\\/+/', '/', '/' . $uri); $strict = $strict === null ? $this->default_strict_matching : $strict; Verify::isTrue($cur->insert($realpath, $invoke, $strict), "repeated path {$realpath}"); Logger::debug("api: {$http_method} {$realpath} => {$class_name}::{$entry[1]->method_name} ok, strict:{$strict}"); } } Logger::debug("load api: {$class_name}, {$class_file} ok"); }