From 2cfeabf05e54d83afb61434117c75e1c9dd7cc01 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 8 Apr 2024 12:19:31 +0200 Subject: [PATCH 1/7] new directory structure --- app/{Router => Core}/RouterFactory.php | 2 +- app/{Presenters/templates => UI}/@layout.latte | 0 .../templates/Error => UI/Error/Error4xx}/403.latte | 0 .../templates/Error => UI/Error/Error4xx}/404.latte | 0 .../templates/Error => UI/Error/Error4xx}/410.latte | 0 .../templates/Error => UI/Error/Error4xx}/4xx.latte | 0 app/{Presenters => UI/Error/Error4xx}/Error4xxPresenter.php | 6 +++--- .../templates/Error => UI/Error/Error5xx}/500.phtml | 0 .../templates/Error => UI/Error/Error5xx}/503.phtml | 0 app/{Presenters => UI/Error/Error5xx}/Error5xxPresenter.php | 4 ++-- app/{Presenters => UI/Home}/HomePresenter.php | 2 +- app/{Presenters/templates => UI}/Home/default.latte | 0 config/common.neon | 6 +++--- config/services.neon | 2 +- 14 files changed, 11 insertions(+), 11 deletions(-) rename app/{Router => Core}/RouterFactory.php (93%) rename app/{Presenters/templates => UI}/@layout.latte (100%) rename app/{Presenters/templates/Error => UI/Error/Error4xx}/403.latte (100%) rename app/{Presenters/templates/Error => UI/Error/Error4xx}/404.latte (100%) rename app/{Presenters/templates/Error => UI/Error/Error4xx}/410.latte (100%) rename app/{Presenters/templates/Error => UI/Error/Error4xx}/4xx.latte (100%) rename app/{Presenters => UI/Error/Error4xx}/Error4xxPresenter.php (79%) rename app/{Presenters/templates/Error => UI/Error/Error5xx}/500.phtml (100%) rename app/{Presenters/templates/Error => UI/Error/Error5xx}/503.phtml (100%) rename app/{Presenters => UI/Error/Error5xx}/Error5xxPresenter.php (91%) rename app/{Presenters => UI/Home}/HomePresenter.php (81%) rename app/{Presenters/templates => UI}/Home/default.latte (100%) diff --git a/app/Router/RouterFactory.php b/app/Core/RouterFactory.php similarity index 93% rename from app/Router/RouterFactory.php rename to app/Core/RouterFactory.php index f5cfbf93..3b1a2855 100644 --- a/app/Router/RouterFactory.php +++ b/app/Core/RouterFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Router; +namespace App\Core; use Nette; use Nette\Application\Routers\RouteList; diff --git a/app/Presenters/templates/@layout.latte b/app/UI/@layout.latte similarity index 100% rename from app/Presenters/templates/@layout.latte rename to app/UI/@layout.latte diff --git a/app/Presenters/templates/Error/403.latte b/app/UI/Error/Error4xx/403.latte similarity index 100% rename from app/Presenters/templates/Error/403.latte rename to app/UI/Error/Error4xx/403.latte diff --git a/app/Presenters/templates/Error/404.latte b/app/UI/Error/Error4xx/404.latte similarity index 100% rename from app/Presenters/templates/Error/404.latte rename to app/UI/Error/Error4xx/404.latte diff --git a/app/Presenters/templates/Error/410.latte b/app/UI/Error/Error4xx/410.latte similarity index 100% rename from app/Presenters/templates/Error/410.latte rename to app/UI/Error/Error4xx/410.latte diff --git a/app/Presenters/templates/Error/4xx.latte b/app/UI/Error/Error4xx/4xx.latte similarity index 100% rename from app/Presenters/templates/Error/4xx.latte rename to app/UI/Error/Error4xx/4xx.latte diff --git a/app/Presenters/Error4xxPresenter.php b/app/UI/Error/Error4xx/Error4xxPresenter.php similarity index 79% rename from app/Presenters/Error4xxPresenter.php rename to app/UI/Error/Error4xx/Error4xxPresenter.php index 014d0ef9..6d6f445f 100644 --- a/app/Presenters/Error4xxPresenter.php +++ b/app/UI/Error/Error4xx/Error4xxPresenter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Presenters; +namespace App\UI\Error\Error4xx; use Nette; use Nette\Application\Attributes\Requires; @@ -18,9 +18,9 @@ public function renderDefault(Nette\Application\BadRequestException $exception): { // renders the appropriate error template based on the HTTP status code $code = $exception->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/config/common.neon b/config/common.neon index 306996ea..4a3a141c 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: 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: From 2317fd5198de748055baf74cd0bcd4de6bdca3ba Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 10 May 2024 14:29:58 +0200 Subject: [PATCH 2/7] added LatteExtension --- app/UI/Accessory/LatteExtension.php | 22 ++++++++++++++++++++++ config/common.neon | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 app/UI/Accessory/LatteExtension.php 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 @@ + Date: Fri, 24 May 2024 16:15:50 +0200 Subject: [PATCH 3/7] composer: updated license --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From e3953c27023f20af349b2f33a7d270d82eab30a6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 3 Aug 2024 18:22:11 +0200 Subject: [PATCH 4/7] Bootstrap: $appDir -> $rootDir [Closes #39] --- app/Bootstrap.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Bootstrap.php b/app/Bootstrap.php index 3aad9300..8c0e74c1 100644 --- a/app/Bootstrap.php +++ b/app/Bootstrap.php @@ -12,19 +12,19 @@ class Bootstrap public static function boot(): Configurator { $configurator = new Configurator; - $appDir = dirname(__DIR__); + $rootDir = dirname(__DIR__); //$configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP - $configurator->enableTracy($appDir . '/log'); + $configurator->enableTracy($rootDir . '/log'); - $configurator->setTempDirectory($appDir . '/temp'); + $configurator->setTempDirectory($rootDir . '/temp'); $configurator->createRobotLoader() ->addDirectory(__DIR__) ->register(); - $configurator->addConfig($appDir . '/config/common.neon'); - $configurator->addConfig($appDir . '/config/services.neon'); + $configurator->addConfig($rootDir . '/config/common.neon'); + $configurator->addConfig($rootDir . '/config/services.neon'); return $configurator; } From 48290a15b3673da83317994df4f0b3f2d51dcb4f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 6 Aug 2024 02:29:44 +0200 Subject: [PATCH 5/7] shorter unpkg link --- app/UI/@layout.latte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/UI/@layout.latte b/app/UI/@layout.latte index b8b55ae5..d3b99338 100644 --- a/app/UI/@layout.latte +++ b/app/UI/@layout.latte @@ -13,7 +13,7 @@ {include content} {block scripts} - + {/block} From 53fb0124dca2fa87d6f33044dae1ee39e9b9f3c8 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 15 Oct 2024 01:45:47 +0200 Subject: [PATCH 6/7] Bootstrap: new API --- app/Bootstrap.php | 39 +++++++++++++++++++++++++++++---------- www/index.php | 4 ++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/Bootstrap.php b/app/Bootstrap.php index 8c0e74c1..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; - $rootDir = dirname(__DIR__); + $this->initializeEnvironment(); + $this->setupContainer(); + return $this->configurator->createContainer(); + } - //$configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP - $configurator->enableTracy($rootDir . '/log'); - $configurator->setTempDirectory($rootDir . '/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($rootDir . '/config/common.neon'); - $configurator->addConfig($rootDir . '/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/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(); From c7607bf883305cf4fa96a661b68d1475bd50c9fa Mon Sep 17 00:00:00 2001 From: "milos.brecher" Date: Thu, 28 Nov 2024 03:53:58 +0100 Subject: [PATCH 7/7] removing useless trait Nette\StaticClass --- app/Core/RouterFactory.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Core/RouterFactory.php b/app/Core/RouterFactory.php index 3b1a2855..14dfd764 100644 --- a/app/Core/RouterFactory.php +++ b/app/Core/RouterFactory.php @@ -4,13 +4,11 @@ namespace App\Core; -use Nette; use Nette\Application\Routers\RouteList; final class RouterFactory { - use Nette\StaticClass; public static function createRouter(): RouteList {