container->get('translator'); } /** * @return LoggerInterface $logger */ private function getLogger() { return $this->container->get('logger'); } /** * Adds a "successful" flash message to the stack. * * @param string $translationKey * @param array $parameter */ protected function flashSuccess($translationKey, $parameter = []) { $this->addFlashTranslated('success', $translationKey, $parameter); } /** * Adds a "warning" flash message to the stack. * * @param string $translationKey * @param array $parameter */ protected function flashWarning($translationKey, $parameter = []) { $this->addFlashTranslated('warning', $translationKey, $parameter); } /** * Adds a "error" flash message to the stack. * * @param string $translationKey * @param array $parameter */ protected function flashError($translationKey, $parameter = []) { $this->addFlashTranslated('error', $translationKey, $parameter); } /** * Adds a fully translated (both $message and all keys in $parameter) flash message to the stack. * * @param string $type * @param string $message * @param array $parameter */ protected function addFlashTranslated(string $type, string $message, array $parameter = []) { if (!empty($parameter)) { foreach ($parameter as $key => $value) { $parameter[$key] = $this->getTranslator()->trans($value, [], 'flashmessages'); } $message = $this->getTranslator()->trans( $message, $parameter, 'flashmessages' ); } $this->addFlash($type, $message); } protected function logException(\Exception $ex) { $this->getLogger()->critical($ex->getMessage()); } public static function getSubscribedServices() { return array_merge(parent::getSubscribedServices(), [ 'translator' => TranslatorInterface::class, 'logger' => LoggerInterface::class, LanguageFormattings::class => LanguageFormattings::class, ]); } protected function getDateTimeFactory(?User $user = null): DateTimeFactory { if (null === $user) { $user = $this->getUser(); } return new DateTimeFactory(new \DateTimeZone($user->getTimezone())); } protected function getLocaleFormats(string $locale): LocaleFormats { return new LocaleFormats($this->container->get(LanguageFormattings::class), $locale); } }