Container compilation configuration improvements

This commit is contained in:
Chris Kankiewicz
2021-04-27 12:48:58 -07:00
parent 5a53e16883
commit 2b49d1bd20
3 changed files with 10 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ class BootManager
...glob($configPath . '/*.php')
);
if (self::enableContainerCompilation()) {
if (self::containerCompilationEnabled()) {
$container->enableCompilation($cachePath);
}
@@ -22,16 +22,18 @@ class BootManager
}
/** Determine if container compilation should be enabled. */
protected static function enableContainerCompilation(): bool
protected static function containerCompilationEnabled(): bool
{
if (filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOL)) {
return false;
}
if (! filter_var(getenv('COMPILE_CONTAINER'), FILTER_VALIDATE_BOOL)) {
return false;
$compileContainer = getenv('COMPILE_CONTAINER');
if ($compileContainer === false) {
return true;
}
return true;
return strtolower($compileContainer) !== 'false';
}
}

View File

@@ -2,7 +2,6 @@
use App\Bootstrap\AppManager;
use App\Bootstrap\BootManager;
use DI\ContainerBuilder;
use Dotenv\Dotenv;
require __DIR__ . '/app/vendor/autoload.php';

View File

@@ -22,10 +22,9 @@ class BootManagerTest extends TestCase
}
/** @test */
public function it_caches_the_container_when_compile_container_is_true(): void
public function it_caches_the_container_by_default(): void
{
putenv('APP_DEBUG=false');
putenv('COMPILE_CONTAINER=true');
putenv('COMPILE_CONTAINER=');
$container = BootManager::createContainer(
$this->filePath('app/config'),
@@ -37,9 +36,8 @@ class BootManagerTest extends TestCase
}
/** @test */
public function it_does_not_cache_the_container_when_compilation_is_explicitly_disabled(): void
public function it_does_not_cache_the_container_when_explicitly_disabled(): void
{
putenv('APP_DEBUG=false');
putenv('COMPILE_CONTAINER=false');
$container = BootManager::createContainer(
@@ -55,7 +53,6 @@ class BootManagerTest extends TestCase
public function it_does_not_cache_the_container_when_debug_is_enabled(): void
{
putenv('APP_DEBUG=true');
putenv('COMPILE_CONTAINER=true');
$container = BootManager::createContainer(
$this->filePath('app/config'),