예제 #1
0
 public static function readAllRoutes()
 {
     $filePaths = \SoftUni\Core\Annotations::getDirContents($_SERVER['DOCUMENT_ROOT']);
     $routeConfigFilePaths = self::getAllRouteConfigFilePaths($filePaths);
     self::$routes = [];
     foreach ($routeConfigFilePaths as $routeConfigFilePath) {
         //var_dump($routeConfigFilePath);
         $routePath = array_pop($routeConfigFilePath);
         //var_dump($routePath);
         require_once $routePath;
         if (preg_match('/Areas(.*?)Config/i', $routePath, $match)) {
             $area = str_replace('\\', '', $match[1]);
             $area = str_replace('/', '', $area);
             self::$routes['Area'] = array($area => $routes);
         }
         if (preg_match('#(Application)[\\\\/]Config#i', $routePath, $match)) {
             self::$routes['Application'] = $routes;
         }
         if (preg_match('#(Framework)[\\\\/]Config#i', $routePath, $match)) {
             self::$routes['Framework'] = $routes;
         }
     }
     $routesFromAnnotations = \SoftUni\Core\Annotations::$allAnnotations['Routes'];
     self::$routes['Annotations'] = $routesFromAnnotations;
 }
 public static function init()
 {
     spl_autoload_register(function ($class) {
         // remove vendor from the class path
         $position = stripos($class, "\\");
         $class = substr($class, $position);
         $class = str_replace('\\', '\\\\', $class);
         // find proper file for this class
         $dirs = Annotations::getDirContents($_SERVER['DOCUMENT_ROOT']);
         $classFile = array_filter($dirs, function ($dir) use($class) {
             $pattern = '/' . $class . '/';
             if (preg_match($pattern, $dir)) {
                 return $dir;
             }
         });
         // require the file if it is found
         $firstMatchedFile = array_pop($classFile);
         if (isset($firstMatchedFile)) {
             require_once $firstMatchedFile;
         }
     });
 }