src/Router.php
protected function parseFile($file)
    {
        $result = '';
        $routes = [];

        //Windows
        $appDir = str_replace('web/../app/', '', APP_DIR);
        //All
        $appDir = str_replace('web' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . '',
            '', APP_DIR);

        $task = str_replace($appDir . 'app' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . '', '', $file);
        $task = rtrim($task, '.php');
        $task = str_replace(DIRECTORY_SEPARATOR, ',', $task);

        // We load file content
        $content = file_get_contents($file);
        // We search for namespace
        $namespace = null;

        if (preg_match('/namespace\s+([\w\\\_-]+)/', $content, $matches) === 1) {
            $namespace = $matches[1];
        }

        // We look for class name
        if (preg_match('/class\s+([\w_-]+)/', $content, $matches) === 1) {
            $className = ($namespace !== null) ? $namespace . '\\' . $matches[1] : $matches[1];
            // We find class info's
            $path = str_replace('Controller.php', '.php', $className . '.php');
            $path = APP_DIR . str_replace('\\', '/', $path);
            if (is_file($path)) {
                include_once $path;
            }
            $reflector = new \ReflectionClass($className);
            $prefix = '';
            if (preg_match('/@RoutePrefix\(["\'](((?!(["\'])).)*)["\']\)/', $reflector->getDocComment(),
                    $matches) === 1) {
                $prefix = $matches[1];
            }
            $methods = $reflector->getMethods(\ReflectionMethod::IS_PUBLIC);
            $result = '';

            $vars = null;
            foreach ($methods as $m) {
                $vars = null;
                if ($m->isStatic()) {
                    continue;
                }

                if (preg_match('/@Route\(\s*(.*)*\)/', $m->getDocComment(), $matches) === 1) {
                    preg_match_all('/(?![(@Route()])([@a-zA-Z0-9"[\]:_> \'(.*)\/[=])+["]/', $matches[0], $route2);
                    $routeName = null;
                    if (preg_match('/name=["](.*)["]/', $route2[0][1], $matches)) {
                        $routeName = $matches[1];
                    }
                    if (empty($routeName)) {
                        throw new InvalidArgumentException('Incorrect name', 403);
                    }

                    $routePath = trim($route2[0][0], '"');
                    $routePath = trim($routePath);
                    $routePath = ltrim($routePath, '/');
                    $lChar = substr($routePath, -1);
                    if ($lChar == ']') {
                        $routePath = $routePath . '/';
                    }
                    preg_match_all('!\[(.+?)\]!i', $routePath, $expression_);
                    $iCount = count($expression_[0]);
                    for ($i = 0; $i < $iCount; $i++) {
                        if ($expression_[0][$i] != '[params]') {
                            $vars .= '&' . $expression_[1][$i] . '=' . $expression_[0][$i];
                        }
                    }
                    $routes[$routePath] = [
                        'routeName' => $routeName,
                        'routePath' => $routePath,
                        'task' => $task,
                        'action' => $m->name,
                        'substring' => $vars,
                    ];
                }
            }

            return $routes;
        }

        return null;
    }
protected function parseFile($file)
    {
        $result = '';
        $routes = [];

        //Windows
        $appDir = str_replace('web/../app/', '', APP_DIR);
        //All
        $appDir = str_replace('web' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . '',
            '', APP_DIR);

        $task = str_replace($appDir . 'app' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . '', '', $file);
        $task = rtrim($task, '.php');
        $task = str_replace(DIRECTORY_SEPARATOR, ',', $task);

        // We load file content
        $content = file_get_contents($file);
        // We search for namespace
        $namespace = null;

        if (preg_match('/namespace\s+([\w\\\_-]+)/', $content, $matches) === 1) {
            $namespace = $matches[1];
        }

        // We look for class name
        if (preg_match('/class\s+([\w_-]+)/', $content, $matches) === 1) {
            $className = ($namespace !== null) ? $namespace . '\\' . $matches[1] : $matches[1];
            // We find class info's
            $path = str_replace('Controller.php', '.php', $className . '.php');
            $path = APP_DIR . str_replace('\\', '/', $path);
            if (is_file($path)) {
                include_once $path;
            }
            $reflector = new \ReflectionClass($className);
            $prefix = '';
            if (preg_match('/@RoutePrefix\(["\'](((?!(["\'])).)*)["\']\)/', $reflector->getDocComment(),
                    $matches) === 1) {
                $prefix = $matches[1];
            }
            $methods = $reflector->getMethods(\ReflectionMethod::IS_PUBLIC);
            $result = '';

            $vars = null;
            foreach ($methods as $m) {
                $vars = null;
                if ($m->isStatic()) {
                    continue;
                }

                if (preg_match('/@Route\(\s*(.*)*\)/', $m->getDocComment(), $matches) === 1) {
                    preg_match_all('/(?![(@Route()])([@a-zA-Z0-9"[\]:_> \'(.*)\/[=])+["]/', $matches[0], $route2);
                    $routeName = null;
                    if (preg_match('/name=["](.*)["]/', $route2[0][1], $matches)) {
                        $routeName = $matches[1];
                    }
                    if (empty($routeName)) {
                        throw new InvalidArgumentException('Incorrect name', 403);
                    }

                    $routePath = trim($route2[0][0], '"');
                    $routePath = trim($routePath);
                    $routePath = ltrim($routePath, '/');
                    $lChar = substr($routePath, -1);
                    if ($lChar == ']') {
                        $routePath = $routePath . '/';
                    }
                    preg_match_all('!\[(.+?)\]!i', $routePath, $expression_);
                    $iCount = count($expression_[0]);
                    for ($i = 0; $i < $iCount; $i++) {
                        if ($expression_[0][$i] != '[params]') {
                            $vars .= '&' . $expression_[1][$i] . '=' . $expression_[0][$i];
                        }
                    }
                    $routes[$routePath] = [
                        'routeName' => $routeName,
                        'routePath' => $routePath,
                        'task' => $task,
                        'action' => $m->name,
                        'substring' => $vars,
                    ];
                }
            }

            return $routes;
        }

        return null;
    }
protected function parseFile ( $ file ) { $ result = '' ; $ routes = [ ] ; //Windows $ appDir = str_replace ( 'web/../app/' , '' , APP_DIR ) ; //All $ appDir = str_replace ( 'web' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . '' , '' , APP_DIR ) ; $ task = str_replace ( $ appDir . 'app' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . '' , '' , $ file ) ; $ task = rtrim ( $ task , '.php' ) ; $ task = str_replace ( DIRECTORY_SEPARATOR , ',' , $ task ) ; // We load file content $ content = file_get_contents ( $ file ) ; // We search for namespace $ namespace = null ; if ( preg_match ( '/namespace\s+([\w\\\_-]+)/' , $ content , $ matches ) === 1 ) { $ namespace = $ matches [ 1 ] ; } // We look for class name if ( preg_match ( '/class\s+([\w_-]+)/' , $ content , $ matches ) === 1 ) { $ className = ( $ namespace !== null ) ? $ namespace . '\\' . $ matches [ 1 ] : $ matches [ 1 ] ; // We find class info's $ path = str_replace ( 'Controller.php' , '.php' , $ className . '.php' ) ; $ path = APP_DIR . str_replace ( '\\' , '/' , $ path ) ; if ( is_file ( $ path ) ) { include_once $ path ; } $ reflector = new \ ReflectionClass ( $ className ) ; $ prefix = '' ; if ( preg_match ( '/@RoutePrefix\(["\'](((?!(["\'])).)*)["\']\)/' , $ reflector -> getDocComment ( ) , $ matches ) === 1 ) { $ prefix = $ matches [ 1 ] ; } $ methods = $ reflector -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) ; $ result = '' ; $ vars = null ; foreach ( $ methods as $ m ) { $ vars = null ; if ( $ m -> isStatic ( ) ) { continue ; } if ( preg_match ( '/@Route\(\s*(.*)*\)/' , $ m -> getDocComment ( ) , $ matches ) === 1 ) { preg_match_all ( '/(?![(@Route()])([@a-zA-Z0-9"[\]:_> \'(.*)\/[=])+["]/' , $ matches [ 0 ] , $ route2 ) ; $ routeName = null ; if ( preg_match ( '/name=["](.*)["]/' , $ route2 [ 0 ] [ 1 ] , $ matches ) ) { $ routeName = $ matches [ 1 ] ; } if ( empty ( $ routeName ) ) { throw new InvalidArgumentException ( 'Incorrect name' , 403 ) ; } $ routePath = trim ( $ route2 [ 0 ] [ 0 ] , '"' ) ; $ routePath = trim ( $ routePath ) ; $ routePath = ltrim ( $ routePath , '/' ) ; $ lChar = substr ( $ routePath , - 1 ) ; if ( $ lChar == ']' ) { $ routePath = $ routePath . '/' ; } preg_match_all ( '!\[(.+?)\]!i' , $ routePath , $ expression_ ) ; $ iCount = count ( $ expression_ [ 0 ] ) ; for ( $ i = 0 ; $ i < $ iCount ; $ i ++ ) { if ( $ expression_ [ 0 ] [ $ i ] != '[params]' ) { $ vars .= '&' . $ expression_ [ 1 ] [ $ i ] . '=' . $ expression_ [ 0 ] [ $ i ] ; } } $ routes [ $ routePath ] = [ 'routeName' => $ routeName , 'routePath' => $ routePath , 'task' => $ task , 'action' => $ m -> name , 'substring' => $ vars , ] ; } } return $ routes ; } return null ; }
Parsing annotations

@param string $file

@return string|array
Parsing annotations