/** * @param Container $container * * @return void */ protected static function setUpPdo(Container $container) { $container[PDO::class] = function (ContainerInterface $container) { $dbConfig = $container->get(ConfigInterface::class)->getConfig(C::class); $pdo = new PDO($dbConfig[C::PDO_CONNECTION_STRING], $dbConfig[C::USER_NAME], $dbConfig[C::PASSWORD], $dbConfig[C::PDO_OPTIONS]); return $pdo; }; }
/** * @param Container $container * * @return void */ protected static function setUpHasher(Container $container) { $container[HasherInterface::class] = function (ContainerInterface $container) { $cryptConfig = $container->get(ConfigInterface::class)->getConfig(C::class); $hasher = new Hasher($cryptConfig[C::HASH_ALGORITHM], $cryptConfig[C::HASH_COST]); return $hasher; }; }
/** * @param Container $container * * @return void */ protected static function setUpTemplates(Container $container) { $container[TemplatesInterface::class] = function (ContainerInterface $container) { $tplConfig = $container->get(ConfigInterface::class)->getConfig(C::class); $templateEngine = new TwigTemplates($tplConfig[C::TEMPLATES_FOLDER], $tplConfig[C::CACHE_FOLDER]); return $templateEngine; }; }
/** * @param Container $container * * @return void * * @SuppressWarnings(PHPMD.StaticAccess) */ protected static function setUpCors(Container $container) { $container[AnalyzerInterface::class] = function (ContainerInterface $container) { /** @var ConfigInterface $config */ $config = $container->get(ConfigInterface::class); $appConfig = $config->getConfig(Application::class); $strategy = new Settings($config->getConfig(Settings::class)); $analyzer = Analyzer::instance($strategy); if ($appConfig[Application::KEY_IS_LOG_ENABLED] === true) { $logger = $container->get(LoggerInterface::class); $analyzer->setLogger($logger); } return $analyzer; }; }
/** * @param Container $container * * @return void * * @SuppressWarnings(PHPMD.ElseExpression) */ protected static function setUpNetworkLogs(Container $container) { $container[LoggerInterface::class] = function (Container $container) { $appConfig = $container->get(ConfigInterface::class)->getConfig(C::class); $monolog = new Logger($appConfig[C::KEY_NAME]); if ($appConfig[C::KEY_IS_LOG_ENABLED] === true) { $handler = new SocketHandler('udp://localhost:8081', $appConfig[C::KEY_LOG_LEVEL]); $handler->pushProcessor(new WebProcessor()); $handler->pushProcessor(new UidProcessor()); } else { $handler = new NullHandler(); } $monolog->pushHandler($handler); return $monolog; }; }