jidaikobo-shibata /
kontiki-framework
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Jidaikobo\Kontiki; |
||
| 4 | |||
| 5 | use DI\Container; |
||
| 6 | use Dotenv\Dotenv; |
||
| 7 | use Slim\Factory\AppFactory; |
||
| 8 | use Slim\App; |
||
| 9 | use Jidaikobo\Log; |
||
| 10 | use Jidaikobo\Kontiki\Middleware\AuthMiddleware; |
||
| 11 | use Jidaikobo\Kontiki\Middleware\SecurityHeadersMiddleware; |
||
| 12 | |||
| 13 | class Bootstrap |
||
| 14 | { |
||
| 15 | public static function init(string $env = 'production') |
||
| 16 | { |
||
| 17 | // check response performance |
||
| 18 | $GLOBALS['KONTIKI_START_TIME'] = microtime(true); |
||
| 19 | |||
| 20 | // Set the error log handler |
||
| 21 | Log::getInstance()->registerHandlers(); |
||
| 22 | |||
| 23 | // load config |
||
| 24 | $projectPath = $env == 'development' ? dirname(__DIR__) : dirname(__DIR__, 4); |
||
| 25 | $dotenv = Dotenv::createImmutable($projectPath . "/config/{$env}/"); |
||
| 26 | $dotenv->load(); |
||
| 27 | |||
| 28 | // Load Functions |
||
| 29 | require __DIR__ . '/functions/functions.php'; |
||
| 30 | |||
| 31 | // setenv |
||
| 32 | setenv('ENV', $env); |
||
| 33 | setenv('PROJECT_PATH', $projectPath); |
||
| 34 | |||
| 35 | // Load default language on class load |
||
| 36 | $language = env('APPLANG', 'en'); |
||
| 37 | Utils\Lang::setLanguage($language); |
||
| 38 | |||
| 39 | // Configure a PHP-DI container |
||
| 40 | $container = new Container(); |
||
| 41 | AppFactory::setContainer($container); |
||
| 42 | |||
| 43 | // Create a Slim application |
||
| 44 | $app = AppFactory::create(); |
||
| 45 | $app->addErrorMiddleware(true, true, true); |
||
| 46 | $basePath = env('BASEPATH', '/'); |
||
| 47 | $app->setBasePath($basePath); |
||
| 48 | |||
| 49 | // Add auth check |
||
| 50 | $app->add(AuthMiddleware::class); |
||
| 51 | |||
| 52 | // Add headers for security measures |
||
| 53 | $app->add(SecurityHeadersMiddleware::class); |
||
| 54 | |||
| 55 | // Set dependencies |
||
| 56 | $dependencies = new Config\Dependencies($app); |
||
| 57 | $dependencies->register(); |
||
| 58 | |||
| 59 | // Set Route |
||
| 60 | $auth = $app->getContainer()->get(Core\Auth::class); |
||
| 61 | $routesClass = class_exists('App\Config\Routes') |
||
| 62 | ? new \App\Config\Routes() |
||
|
0 ignored issues
–
show
|
|||
| 63 | : new \Jidaikobo\Kontiki\Config\Routes(); |
||
| 64 | $routesClass->register($app, $container, $auth); |
||
| 65 | |||
| 66 | return $app; |
||
| 67 | } |
||
| 68 | |||
| 69 | public static function run(App $app): void |
||
| 70 | { |
||
| 71 | $app->run(); |
||
| 72 | self::performance(); |
||
| 73 | } |
||
| 74 | |||
| 75 | public static function performance($timer = false): void |
||
| 76 | { |
||
| 77 | // $timer = true; |
||
| 78 | if ($timer) { |
||
| 79 | $elapsedTime = microtime(true) - $GLOBALS['KONTIKI_START_TIME']; |
||
| 80 | jlog("Total execution time: " . number_format($elapsedTime, 6) . " seconds"); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths