diff --git a/app/Bootstrap.php b/app/Bootstrap.php index 3aad9300..17244989 100644 --- a/app/Bootstrap.php +++ b/app/Bootstrap.php @@ -4,28 +4,47 @@ namespace App; +use Nette; use Nette\Bootstrap\Configurator; class Bootstrap { - public static function boot(): Configurator + private Configurator $configurator; + private string $rootDir; + + + public function __construct() + { + $this->rootDir = dirname(__DIR__); + $this->configurator = new Configurator; + $this->configurator->setTempDirectory($this->rootDir . '/temp'); + } + + + public function bootWebApplication(): Nette\DI\Container { - $configurator = new Configurator; - $appDir = dirname(__DIR__); + $this->initializeEnvironment(); + $this->setupContainer(); + return $this->configurator->createContainer(); + } - //$configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP - $configurator->enableTracy($appDir . '/log'); - $configurator->setTempDirectory($appDir . '/temp'); + public function initializeEnvironment(): void + { + //$this->configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP + $this->configurator->enableTracy($this->rootDir . '/log'); - $configurator->createRobotLoader() + $this->configurator->createRobotLoader() ->addDirectory(__DIR__) ->register(); + } - $configurator->addConfig($appDir . '/config/common.neon'); - $configurator->addConfig($appDir . '/config/services.neon'); - return $configurator; + private function setupContainer(): void + { + $configDir = $this->rootDir . '/config'; + $this->configurator->addConfig($configDir . '/common.neon'); + $this->configurator->addConfig($configDir . '/services.neon'); } } diff --git a/app/Router/RouterFactory.php b/app/Core/RouterFactory.php similarity index 82% rename from app/Router/RouterFactory.php rename to app/Core/RouterFactory.php index f5cfbf93..14dfd764 100644 --- a/app/Router/RouterFactory.php +++ b/app/Core/RouterFactory.php @@ -2,15 +2,13 @@ declare(strict_types=1); -namespace App\Router; +namespace App\Core; -use Nette; use Nette\Application\Routers\RouteList; final class RouterFactory { - use Nette\StaticClass; public static function createRouter(): RouteList { diff --git a/app/Presenters/templates/@layout.latte b/app/UI/@layout.latte similarity index 81% rename from app/Presenters/templates/@layout.latte rename to app/UI/@layout.latte index b8b55ae5..d3b99338 100644 --- a/app/Presenters/templates/@layout.latte +++ b/app/UI/@layout.latte @@ -13,7 +13,7 @@ {include content} {block scripts} - + {/block} diff --git a/app/UI/Accessory/LatteExtension.php b/app/UI/Accessory/LatteExtension.php new file mode 100644 index 00000000..c5fba704 --- /dev/null +++ b/app/UI/Accessory/LatteExtension.php @@ -0,0 +1,22 @@ +getCode(); - $file = is_file($file = __DIR__ . "/templates/Error/$code.latte") + $file = is_file($file = __DIR__ . "/$code.latte") ? $file - : __DIR__ . '/templates/Error/4xx.latte'; + : __DIR__ . '/4xx.latte'; $this->template->httpCode = $code; $this->template->setFile($file); } diff --git a/app/Presenters/templates/Error/500.phtml b/app/UI/Error/Error5xx/500.phtml similarity index 100% rename from app/Presenters/templates/Error/500.phtml rename to app/UI/Error/Error5xx/500.phtml diff --git a/app/Presenters/templates/Error/503.phtml b/app/UI/Error/Error5xx/503.phtml similarity index 100% rename from app/Presenters/templates/Error/503.phtml rename to app/UI/Error/Error5xx/503.phtml diff --git a/app/Presenters/Error5xxPresenter.php b/app/UI/Error/Error5xx/Error5xxPresenter.php similarity index 91% rename from app/Presenters/Error5xxPresenter.php rename to app/UI/Error/Error5xx/Error5xxPresenter.php index f0cf401b..247f00b8 100644 --- a/app/Presenters/Error5xxPresenter.php +++ b/app/UI/Error/Error5xx/Error5xxPresenter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Presenters; +namespace App\UI\Error\Error5xx; use Nette; use Nette\Application\Attributes\Requires; @@ -32,7 +32,7 @@ public function run(Nette\Application\Request $request): Nette\Application\Respo // Display a generic error message to the user return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void { if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) { - require __DIR__ . '/templates/Error/500.phtml'; + require __DIR__ . '/500.phtml'; } }); } diff --git a/app/Presenters/HomePresenter.php b/app/UI/Home/HomePresenter.php similarity index 81% rename from app/Presenters/HomePresenter.php rename to app/UI/Home/HomePresenter.php index 0af27d45..00806665 100644 --- a/app/Presenters/HomePresenter.php +++ b/app/UI/Home/HomePresenter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Presenters; +namespace App\UI\Home; use Nette; diff --git a/app/Presenters/templates/Home/default.latte b/app/UI/Home/default.latte similarity index 100% rename from app/Presenters/templates/Home/default.latte rename to app/UI/Home/default.latte diff --git a/composer.json b/composer.json index 477c968d..00513bef 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Nette: Standard Web Project", "keywords": ["nette"], "type": "project", - "license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"], + "license": ["MIT", "BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"], "require": { "php": ">= 8.1", "nette/application": "^3.2.3", diff --git a/config/common.neon b/config/common.neon index 306996ea..6f7766e7 100644 --- a/config/common.neon +++ b/config/common.neon @@ -3,9 +3,9 @@ parameters: application: errorPresenter: - 4xx: Error4xx - 5xx: Error5xx - mapping: App\*Module\Presenters\*Presenter + 4xx: Error:Error4xx + 5xx: Error:Error5xx + mapping: App\UI\*\**Presenter database: @@ -16,6 +16,9 @@ database: latte: strictTypes: yes + strictParsing: yes + extensions: + - App\UI\Accessory\LatteExtension di: diff --git a/config/services.neon b/config/services.neon index d20e72b2..03a74686 100644 --- a/config/services.neon +++ b/config/services.neon @@ -1,5 +1,5 @@ services: - - App\Router\RouterFactory::createRouter + - App\Core\RouterFactory::createRouter search: diff --git a/www/index.php b/www/index.php index 466a9884..d6e6884a 100644 --- a/www/index.php +++ b/www/index.php @@ -4,7 +4,7 @@ require __DIR__ . '/../vendor/autoload.php'; -$configurator = App\Bootstrap::boot(); -$container = $configurator->createContainer(); +$bootstrap = new App\Bootstrap; +$container = $bootstrap->bootWebApplication(); $application = $container->getByType(Nette\Application\Application::class); $application->run();