Initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
32
src/ContainerFactory.php
Normal file
32
src/ContainerFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Pronchev\Pinecore;
|
||||
|
||||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
class ContainerFactory
|
||||
{
|
||||
public static function build(Environment $env, Config $config, string $basePath): Container
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
|
||||
if ($env->isProd()) {
|
||||
$cacheDir = $basePath . '/var/cache/prod';
|
||||
if (!is_dir($cacheDir)) {
|
||||
mkdir($cacheDir, 0755, true);
|
||||
}
|
||||
$builder->enableCompilation($cacheDir);
|
||||
}
|
||||
|
||||
$builder->useAutowiring(true);
|
||||
|
||||
$servicesFile = $basePath . '/config/services.php';
|
||||
if (file_exists($servicesFile)) {
|
||||
$definitions = require $servicesFile;
|
||||
$definitions($builder, $config, $basePath);
|
||||
}
|
||||
|
||||
return $builder->build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user