BitBagCommerce /
SyliusCmsPlugin
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file was created by developers working at BitBag |
||
| 5 | * Do you need more information about us and what we do? Visit our https://bitbag.io website! |
||
| 6 | * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
||
| 7 | */ |
||
| 8 | |||
| 9 | declare(strict_types=1); |
||
| 10 | |||
| 11 | namespace BitBag\SyliusCmsPlugin\Assigner; |
||
| 12 | |||
| 13 | use BitBag\SyliusCmsPlugin\Entity\SectionableInterface; |
||
| 14 | use BitBag\SyliusCmsPlugin\Entity\SectionInterface; |
||
| 15 | use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface; |
||
| 16 | use Webmozart\Assert\Assert; |
||
| 17 | |||
| 18 | final class SectionsAssigner implements SectionsAssignerInterface |
||
| 19 | { |
||
| 20 | /** @var SectionRepositoryInterface */ |
||
| 21 | private $sectionRepository; |
||
| 22 | |||
| 23 | public function __construct(SectionRepositoryInterface $sectionRepository) |
||
| 24 | { |
||
| 25 | $this->sectionRepository = $sectionRepository; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function assign(SectionableInterface $sectionsAware, array $sectionsCodes): void |
||
| 29 | { |
||
| 30 | foreach ($sectionsCodes as $sectionCode) { |
||
| 31 | /** @var SectionInterface|null $section */ |
||
| 32 | $section = $this->sectionRepository->findOneBy(['code' => $sectionCode]); |
||
| 33 | |||
| 34 | Assert::notNull($section, sprintf('Section with %s code not found.', $sectionCode)); |
||
| 35 | $sectionsAware->addSection($section); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 |