12 use Monolog\Handler\BrowserConsoleHandler;
13 use Monolog\Handler\ErrorLogHandler;
16 use Symfony\Component\Config\FileLocator;
17 use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
18 use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
20 $restCall = (isset($GLOBALS[
'apiCall']) && $GLOBALS[
'apiCall']);
22 $containerClassName =
'FossologyCachedContainer';
24 $cacheDir = array_key_exists(
'CACHEDIR', $GLOBALS) ? $GLOBALS[
'CACHEDIR'] :
null;
25 $cacheFile =
"$cacheDir/container.php";
27 $containerBuilder =
"Symfony\Component\DependencyInjection\ContainerBuilder";
29 $startTime = microtime(
true);
31 $cached = $cacheDir && file_exists($cacheFile);
34 require_once ($cacheFile);
39 $container =
new $containerClassName();
45 $container =
new $containerBuilder();
47 $container->setParameter(
'application_root', dirname(dirname(__DIR__)));
49 $loader =
new XmlFileLoader($container,
new FileLocator(__DIR__));
50 $loader->load(
'services.xml');
52 $container->compile();
54 if ($cacheDir && is_dir($cacheDir)) {
55 $dumper =
new PhpDumper($container);
57 file_put_contents($cacheFile,
59 'class' => $containerClassName
64 if ($restCall && $container->has(
'environment')) {
66 $container->get(
'environment')->replace($_SERVER);
69 $GLOBALS[
'container'] = $container;
70 $logger = $container->get(
'logger');
72 new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::INFO));
73 $logger->pushHandler(
new BrowserConsoleHandler(Logger::DEBUG));
75 $timeZone = $container->getParameter(
'time.zone');
76 if (! empty($timeZone)) {
77 $twig = $container->get(
'twig.environment');
78 $twig->getExtension(
'core')->setTimezone($timeZone);
82 $timingLogger = $container->get(
"log.timing");
83 $timingLogger->logWithStartTime(
84 sprintf(
"DI container setup (cached: %s)", $cached ?
'yes' :
'no'), $startTime);