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 Sylius\Component\Channel\Model\ChannelsAwareInterface; |
||
| 14 | use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
||
| 15 | use Sylius\Component\Core\Model\ChannelInterface; |
||
| 16 | use Webmozart\Assert\Assert; |
||
| 17 | |||
| 18 | final class ChannelsAssigner implements ChannelsAssignerInterface |
||
| 19 | { |
||
| 20 | /** @var ChannelRepositoryInterface */ |
||
| 21 | private $channelRepository; |
||
| 22 | |||
| 23 | public function __construct(ChannelRepositoryInterface $channelRepository) |
||
| 24 | { |
||
| 25 | $this->channelRepository = $channelRepository; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function assign(ChannelsAwareInterface $channelsAware, array $channelsCodes): void |
||
| 29 | { |
||
| 30 | foreach ($channelsCodes as $channelCode) { |
||
| 31 | /** @var ChannelInterface|null $channel */ |
||
| 32 | $channel = $this->channelRepository->findOneBy(['code' => $channelCode]); |
||
| 33 | |||
| 34 | Assert::notNull($channel, sprintf('Channel with %s code not found.', $channelCode)); |
||
| 35 | $channelsAware->addChannel($channel); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 |