. */ namespace App\Services\LabelSystem\PlaceholderProviders; use App\Entity\UserSystem\User; use IntlDateFormatter; use Locale; use Symfony\Component\Security\Core\Security; /** * Provides Placeholders for infos about global infos like Installation name or datetimes. * @package App\Services\LabelSystem\PlaceholderProviders */ class GlobalProviders implements PlaceholderProviderInterface { protected $partdb_title; protected $security; public function __construct(string $partdb_title, Security $security) { $this->partdb_title = $partdb_title; $this->security = $security; } /** * @inheritDoc */ public function replace(string $placeholder, object $label_target, array $options = []): ?string { if ($placeholder === "[[INSTALL_NAME]]") { return $this->partdb_title; } $user = $this->security->getUser(); if ($placeholder === "[[USERNAME]]") { if ($user instanceof User) { return $user->getName(); } return 'anonymous'; } if ($placeholder === "[[USERNAME_FULL]]") { if ($user instanceof User) { return $user->getFullName(true); } return 'anonymous'; } $now = new \DateTime(); if ($placeholder === '[[DATETIME]]') { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, $now->getTimezone() ); return $formatter->format($now); } if ($placeholder === '[[DATE]]') { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::NONE, $now->getTimezone() ); return $formatter->format($now); } if ($placeholder === '[[TIME]]') { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::NONE, IntlDateFormatter::SHORT, $now->getTimezone() ); return $formatter->format($now); } return null; } }