. */ namespace App\Services\LabelSystem\PlaceholderProviders; use App\Entity\Parts\PartLot; use App\Services\AmountFormatter; use App\Services\LabelSystem\LabelTextReplacer; use IntlDateFormatter; use Locale; final class PartLotProvider implements PlaceholderProviderInterface { private LabelTextReplacer $labelTextReplacer; private AmountFormatter $amountFormatter; public function __construct(LabelTextReplacer $labelTextReplacer, AmountFormatter $amountFormatter) { $this->labelTextReplacer = $labelTextReplacer; $this->amountFormatter = $amountFormatter; } public function replace(string $placeholder, object $label_target, array $options = []): ?string { if ($label_target instanceof PartLot) { if ('[[LOT_ID]]' === $placeholder) { return (string) ($label_target->getID() ?? 'unknown'); } if ('[[LOT_NAME]]' === $placeholder) { return $label_target->getName(); } if ('[[LOT_COMMENT]]' === $placeholder) { return $label_target->getComment(); } if ('[[EXPIRATION_DATE]]' === $placeholder) { if (null === $label_target->getExpirationDate()) { return ''; } $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::NONE ); return $formatter->format($label_target->getExpirationDate()); } if ('[[AMOUNT]]' === $placeholder) { if ($label_target->isInstockUnknown()) { return '?'; } return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit()); } if ('[[LOCATION]]' === $placeholder) { return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : ''; } if ('[[LOCATION_FULL]]' === $placeholder) { return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : ''; } return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart()); } return null; } }