Skip to content

Removing useless trait Nette\StaticClass #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions app/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
4 changes: 1 addition & 3 deletions app/Router/RouterFactory.php → app/Core/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{include content}

{block scripts}
<script src="https://unpkg.com/nette-forms@3/src/assets/netteForms.js"></script>
<script src="https://unpkg.com/nette-forms@3"></script>
{/block}
</body>
</html>
22 changes: 22 additions & 0 deletions app/UI/Accessory/LatteExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\UI\Accessory;

use Latte\Extension;


final class LatteExtension extends Extension
{
public function getFilters(): array
{
return [];
}


public function getFunctions(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Presenters;
namespace App\UI\Error\Error4xx;

use Nette;
use Nette\Application\Attributes\Requires;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Presenters;
namespace App\UI\Error\Error5xx;

use Nette;
use Nette\Application\Attributes\Requires;
Expand Down Expand Up @@ -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';
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Presenters;
namespace App\UI\Home;

use Nette;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -16,6 +16,9 @@ database:

latte:
strictTypes: yes
strictParsing: yes
extensions:
- App\UI\Accessory\LatteExtension


di:
Expand Down
2 changes: 1 addition & 1 deletion config/services.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
- App\Router\RouterFactory::createRouter
- App\Core\RouterFactory::createRouter


search:
Expand Down
4 changes: 2 additions & 2 deletions www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();