. */ namespace App\Services\LabelSystem\PlaceholderProviders; use App\Entity\Parts\Part; use App\Services\SIFormatter; use Parsedown; use Symfony\Contracts\Translation\TranslatorInterface; final class PartProvider implements PlaceholderProviderInterface { private SIFormatter $siFormatter; private TranslatorInterface $translator; public function __construct(SIFormatter $SIFormatter, TranslatorInterface $translator) { $this->siFormatter = $SIFormatter; $this->translator = $translator; } public function replace(string $placeholder, object $part, array $options = []): ?string { if (!$part instanceof Part) { return null; } if ('[[CATEGORY]]' === $placeholder) { return $part->getCategory() ? $part->getCategory()->getName() : ''; } if ('[[CATEGORY_FULL]]' === $placeholder) { return $part->getCategory() ? $part->getCategory()->getFullPath() : ''; } if ('[[MANUFACTURER]]' === $placeholder) { return $part->getManufacturer() ? $part->getManufacturer()->getName() : ''; } if ('[[MANUFACTURER_FULL]]' === $placeholder) { return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : ''; } if ('[[FOOTPRINT]]' === $placeholder) { return $part->getFootprint() ? $part->getFootprint()->getName() : ''; } if ('[[FOOTPRINT_FULL]]' === $placeholder) { return $part->getFootprint() ? $part->getFootprint()->getFullPath() : ''; } if ('[[MASS]]' === $placeholder) { return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : ''; } if ('[[MPN]]' === $placeholder) { return $part->getManufacturerProductNumber(); } if ('[[TAGS]]' === $placeholder) { return $part->getTags(); } if ('[[M_STATUS]]' === $placeholder) { if ('' === $part->getManufacturingStatus()) { return ''; } return $this->translator->trans('m_status.'.$part->getManufacturingStatus()); } $parsedown = new Parsedown(); if ('[[DESCRIPTION]]' === $placeholder) { return $parsedown->line($part->getDescription()); } if ('[[DESCRIPTION_T]]' === $placeholder) { return strip_tags($parsedown->line($part->getDescription())); } if ('[[COMMENT]]' === $placeholder) { return $parsedown->line($part->getComment()); } if ('[[COMMENT_T]]' === $placeholder) { return strip_tags($parsedown->line($part->getComment())); } return null; } }