phprs\Router::loadApi PHP Method

loadApi() private method

加载api类
private loadApi ( array &$routes, string $class_file, string $class_name, string $method = null ) : void
$routes array
$class_file string
$class_name string
$method string
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");
    }