63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App;
|
|
|
|
use Nette;
|
|
use Nette\Bootstrap\Configurator;
|
|
|
|
|
|
class Bootstrap
|
|
{
|
|
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
|
|
{
|
|
$this->initializeEnvironment();
|
|
$this->setupContainer();
|
|
return $this->configurator->createContainer();
|
|
}
|
|
|
|
|
|
public function initializeEnvironment(): void
|
|
{
|
|
//$this->configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP
|
|
$this->configurator->setDebugMode(false);
|
|
try {
|
|
if (str_contains($_SERVER['SERVER_NAME'], 'localhost'))
|
|
$this->configurator->setDebugMode(true);
|
|
} catch (\Exception) {
|
|
// nic
|
|
}
|
|
$this->configurator->enableTracy($this->rootDir . '/log');
|
|
|
|
$this->configurator->createRobotLoader()
|
|
->addDirectory(__DIR__)
|
|
->register();
|
|
}
|
|
|
|
|
|
private function setupContainer(): void
|
|
{
|
|
$configDir = $this->rootDir . '/config';
|
|
$this->configurator->addConfig($configDir . '/common.neon');
|
|
$this->configurator->addConfig($configDir . '/services.neon');
|
|
|
|
$localConfig = $configDir . '/local.neon';
|
|
if (is_file($localConfig) && filesize($localConfig) > 0) {
|
|
$this->configurator->addConfig($localConfig);
|
|
}
|
|
}
|
|
}
|