Skip to content

Commit

Permalink
new Bootstrap API
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 26, 2025
1 parent 93ec8d6 commit 62448ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
45 changes: 33 additions & 12 deletions app/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App;

use Nette;
use Nette\Bootstrap\Configurator;


Expand All @@ -12,28 +13,48 @@
*/
class Bootstrap
{
public static function boot(): Configurator
private Configurator $configurator;
private string $rootDir;


public function __construct()
{
$this->rootDir = dirname(__DIR__);

// The configurator is responsible for setting up the application environment and services.
// Learn more at https://doc.nette.org/en/bootstrap
$configurator = new Configurator;
$appDir = dirname(__DIR__);
$this->configurator = new Configurator;

// Set the directory for temporary files generated by Nette (e.g. compiled templates)
$this->configurator->setTempDirectory($this->rootDir . '/temp');
}


public function bootWebApplication(): Nette\DI\Container
{
$this->initializeEnvironment();
$this->setupContainer();
return $this->configurator->createContainer();
}


public function initializeEnvironment(): void
{
// Nette is smart, and the development mode turns on automatically,
// or you can enable for a specific IP address it by uncommenting the following line:
// $configurator->setDebugMode('[email protected]');
// $this->configurator->setDebugMode('[email protected]');

// Enables Tracy: the ultimate "swiss army knife" debugging tool.
// Learn more about Tracy at https://tracy.nette.org
$configurator->enableTracy($appDir . '/log');

// Set the directory for temporary files generated by Nette (e.g. compiled templates)
$configurator->setTempDirectory($appDir . '/temp');
$this->configurator->enableTracy($this->rootDir . '/log');
}

// Add configuration files
$configurator->addConfig($appDir . '/config/common.neon');
$configurator->addConfig($appDir . '/config/services.neon');

return $configurator;
private function setupContainer(): void
{
// Load configuration files
$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 @@ -8,10 +8,10 @@
}

// Initialize the application environment
$configurator = App\Bootstrap::boot();
$bootstrap = new App\Bootstrap;

// Create the Dependency Injection container
$container = $configurator->createContainer();
$container = $bootstrap->bootWebApplication();

// Start the application and handle the incoming request
$application = $container->getByType(Nette\Application\Application::class);
Expand Down

0 comments on commit 62448ce

Please sign in to comment.