Skip to content

Commit 3acfc93

Browse files
committed
new Bootstrap API
1 parent 3649ca5 commit 3acfc93

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

app/Bootstrap.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App;
66

7+
use Nette;
78
use Nette\Bootstrap\Configurator;
89

910

@@ -12,28 +13,48 @@
1213
*/
1314
class Bootstrap
1415
{
15-
public static function boot(): Configurator
16+
private Configurator $configurator;
17+
private string $rootDir;
18+
19+
20+
public function __construct()
1621
{
22+
$this->rootDir = dirname(__DIR__);
23+
1724
// The configurator is responsible for setting up the application environment and services.
1825
// Learn more at https://doc.nette.org/en/bootstrap
19-
$configurator = new Configurator;
20-
$appDir = dirname(__DIR__);
26+
$this->configurator = new Configurator;
27+
28+
// Set the directory for temporary files generated by Nette (e.g. compiled templates)
29+
$this->configurator->setTempDirectory($this->rootDir . '/temp');
30+
}
31+
32+
33+
public function bootWebApplication(): Nette\DI\Container
34+
{
35+
$this->initializeEnvironment();
36+
$this->setupContainer();
37+
return $this->configurator->createContainer();
38+
}
2139

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

2647
// Enables Tracy: the ultimate "swiss army knife" debugging tool.
2748
// Learn more about Tracy at https://tracy.nette.org
28-
$configurator->enableTracy($appDir . '/log');
29-
30-
// Set the directory for temporary files generated by Nette (e.g. compiled templates)
31-
$configurator->setTempDirectory($appDir . '/temp');
49+
$this->configurator->enableTracy($this->rootDir . '/log');
50+
}
3251

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

37-
return $configurator;
53+
private function setupContainer(): void
54+
{
55+
// Load configuration files
56+
$configDir = $this->rootDir . '/config';
57+
$this->configurator->addConfig($configDir . '/common.neon');
58+
$this->configurator->addConfig($configDir . '/services.neon');
3859
}
3960
}

www/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
}
99

1010
// Initialize the application environment
11-
$configurator = App\Bootstrap::boot();
11+
$bootstrap = new App\Bootstrap;
1212

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

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

0 commit comments

Comments
 (0)