Ver código fonte

little refactor

Плотников Роман Вячеславович 3 anos atrás
pai
commit
82a6afd87c
2 arquivos alterados com 12 adições e 19 exclusões
  1. 4 5
      config/path.php
  2. 8 14
      core/bootstrap.php

+ 4 - 5
config/path.php

@@ -1,10 +1,9 @@
 <?php
 return [
+    //Адрес относительно домена
     'root' => '',
-    'classes' => [
-        'app',
-        'core'
-    ],
+    //Настройка директории с маршрутами
     'routes' => 'routes',
+    //Настройка директории с представлениями
     'views' => 'views'
-];
+];

+ 8 - 14
core/bootstrap.php

@@ -1,20 +1,13 @@
 <?php
-
+//Путь до директории с конфигурационными файлами
 const DIR_CONFIG = '/../config';
 
-spl_autoload_register(function ($className) {
-    $paths = include __DIR__ . DIR_CONFIG . '/path.php';
-    $className = str_replace('\\', '/', $className);
+//Подключение автозагрузчика composer
+require_once __DIR__ . '/../vendor/autoload.php';
 
-    foreach ($paths['classes'] as $path) {
-        $filename = $_SERVER['DOCUMENT_ROOT'] . "/$paths[root]/$path/$className.php";
-        if (file_exists($filename)) {
-            require_once $filename;
-        }
-    }
-});
-
-function getConfigs(string $path = DIR_CONFIG): array {
+//Функция, возвращающая массив всех настроек приложения
+function getConfigs(string $path = DIR_CONFIG): array
+{
     $settings = [];
     foreach (scandir(__DIR__ . $path) as $file) {
         $name = explode('.', $file)[0];
@@ -27,4 +20,5 @@ function getConfigs(string $path = DIR_CONFIG): array {
 
 require_once __DIR__ . '/../routes/web.php';
 
-return new Src\Application(new Src\Settings(getConfigs()));
+return new Src\Application(new Src\Settings(getConfigs()));
+