Jacwright\RestServer\RestServer::generateMap PHP Method

generateMap() protected method

protected generateMap ( $class, $basePath )
    protected function generateMap($class, $basePath)
    {
        if (is_object($class)) {
            $reflection = new ReflectionObject($class);
        } elseif (class_exists($class)) {
            $reflection = new ReflectionClass($class);
        }
        $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
        //@todo $reflection might not be instantiated
        foreach ($methods as $method) {
            $doc = $method->getDocComment();
            $noAuth = strpos($doc, '@noAuth') !== false;
            if (preg_match_all('/@url[ \\t]+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)[ \\t]+\\/?(\\S*)/s', $doc, $matches, PREG_SET_ORDER)) {
                $params = $method->getParameters();
                foreach ($matches as $match) {
                    $httpMethod = $match[1];
                    $url = $basePath . $match[2];
                    if ($url && $url[strlen($url) - 1] == '/') {
                        $url = substr($url, 0, -1);
                    }
                    $call = array($class, $method->getName());
                    $args = array();
                    foreach ($params as $param) {
                        $args[$param->getName()] = $param->getPosition();
                    }
                    $call[] = $args;
                    $call[] = null;
                    $call[] = $noAuth;
                    $this->map[$httpMethod][$url] = $call;
                }
            }
        }
    }