Skip to content

Commit

Permalink
Bootstrap: new API
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 2, 2025
1 parent afe72bb commit 32f3937
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
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;
$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');
}
}
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();

0 comments on commit 32f3937

Please sign in to comment.