mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-25 06:51:18 +02:00
Added COMPILE_CONTAINER environment variable option for independantly controlling cotainer compilation
This commit is contained in:
37
app/src/Bootstrap/BootManager.php
Normal file
37
app/src/Bootstrap/BootManager.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bootstrap;
|
||||
|
||||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
class BootManager
|
||||
{
|
||||
/** Create the application service container. */
|
||||
public static function createContainer(string $configDirectory): Container
|
||||
{
|
||||
$container = (new ContainerBuilder)->addDefinitions(
|
||||
...glob($configDirectory . '/*.php')
|
||||
);
|
||||
|
||||
if (self::enableContainerCompilation()) {
|
||||
$container->enableCompilation(dirname(__DIR__, 2) . '/cache');
|
||||
}
|
||||
|
||||
return $container->build();
|
||||
}
|
||||
|
||||
/** Determine if container compilation should be enabled. */
|
||||
protected static function enableContainerCompilation(): bool
|
||||
{
|
||||
if (filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! filter_var(getenv('COMPILE_CONTAINER'), FILTER_VALIDATE_BOOL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
12
index.php
12
index.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Bootstrap\AppManager;
|
||||
use App\Bootstrap\BootManager;
|
||||
use DI\ContainerBuilder;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
@@ -13,17 +14,10 @@ ini_set('open_basedir', __DIR__);
|
||||
Dotenv::createUnsafeImmutable(__DIR__)->safeLoad();
|
||||
|
||||
// Initialize the container
|
||||
$container = (new ContainerBuilder)->addDefinitions(
|
||||
...glob(__DIR__ . '/app/config/*.php')
|
||||
);
|
||||
|
||||
// Compile the container
|
||||
if (! filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOL)) {
|
||||
$container->enableCompilation(__DIR__ . '/app/cache');
|
||||
}
|
||||
$container = BootManager::createContainer(__DIR__ . '/app/config');
|
||||
|
||||
// Initialize the application
|
||||
$app = $container->build()->call(AppManager::class);
|
||||
$app = $container->call(AppManager::class);
|
||||
|
||||
// Engage!
|
||||
$app->run();
|
||||
|
@@ -21,6 +21,7 @@ TIMEZONE="America/Phoenix"
|
||||
|
||||
MAX_HASH_SIZE=1000000000
|
||||
|
||||
COMPILE_CONTAINER=false
|
||||
CACHE_DRIVER=array
|
||||
CACHE_LIFETIME=0
|
||||
|
||||
|
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Bootstrap\BootManager;
|
||||
use App\Config;
|
||||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
use Dotenv\Dotenv;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
@@ -26,9 +26,9 @@ class TestCase extends BaseTestCase
|
||||
{
|
||||
Dotenv::createUnsafeImmutable(__DIR__)->safeLoad();
|
||||
|
||||
$this->container = (new ContainerBuilder)->addDefinitions(
|
||||
...glob(dirname(__DIR__) . '/app/config/*.php')
|
||||
)->build();
|
||||
$this->container = BootManager::createContainer(
|
||||
dirname(__DIR__) . '/app/config'
|
||||
);
|
||||
|
||||
$this->config = new Config($this->container);
|
||||
$this->cache = new ArrayAdapter($this->config->get('cache_lifetime'));
|
||||
|
Reference in New Issue
Block a user