33 $restCall = (isset($GLOBALS[
'apiCall']) && $GLOBALS[
'apiCall']);
35 $containerClassName =
'FossologyCachedContainer';
37 $cacheDir = array_key_exists(
'CACHEDIR', $GLOBALS) ? $GLOBALS[
'CACHEDIR'] : null;
38 $cacheFile =
"$cacheDir/container.php";
40 $containerBuilder =
"Symfony\Component\DependencyInjection\ContainerBuilder";
42 $startTime = microtime(
true);
46 $containerClassName =
'FossologyRestCachedContainer';
47 $cacheFile =
"$cacheDir/rest-container.php";
48 $containerBuilder =
"\Flexsounds\Component\SymfonyContainerSlimBridge\ContainerBuilder";
51 $cached = $cacheDir && file_exists($cacheFile);
54 require_once ($cacheFile);
55 $container =
new $containerClassName();
57 $container =
new $containerBuilder();
59 $container->setParameter(
'application_root', dirname(dirname(__DIR__)));
61 $loader =
new XmlFileLoader($container,
new FileLocator(__DIR__));
62 $loader->load(
'services.xml');
66 $container->set(
'notFoundHandler',
67 function ($request, $response){
69 return $response->withJson($error->getArray(), $error->getCode());
71 $container->set(
'notAllowedHandler',
72 function ($request, $response, $methods){
73 $error =
new Info(405,
75 return $response->withHeader(
'Allow', implode(
', ', $methods))
76 ->withJson($error->getArray(), $error->getCode());
78 $container->set(
'phpErrorHandler',
79 function ($request, $response, $error){
80 $GLOBALS[
'container']->get(
'logger')
82 $error =
new Info(500,
"Something went wrong! Please try again later.",
84 return $response->withJson($error->getArray(), $error->getCode());
86 $phpErrorHandler = $container->get(
'phpErrorHandler');
87 $container->set(
'errorHandler', $phpErrorHandler);
90 $container->compile();
92 if ($cacheDir && is_dir($cacheDir)) {
93 $dumper =
new PhpDumper($container);
95 file_put_contents($cacheFile,
97 'class' => $containerClassName
104 $container->get(
'environment')->replace($_SERVER);
107 $GLOBALS[
'container'] = $container;
108 $logger = $container->get(
'logger');
109 $logger->pushHandler(
110 new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::INFO));
111 $logger->pushHandler(
new BrowserConsoleHandler(Logger::DEBUG));
113 $timeZone = $container->getParameter(
'time.zone');
114 if (! empty($timeZone)) {
115 $twig = $container->get(
'twig.environment');
116 $twig->getExtension(
'core')->setTimezone($timeZone);
120 $timingLogger = $container->get(
"log.timing");
121 $timingLogger->logWithStartTime(
122 sprintf(
"DI container setup (cached: %s)", $cached ?
'yes' :
'no'), $startTime);
Info model to contain general error and return values.