| Total Complexity | 8 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class AddBlocks implements MutatorInterface, RenderableInterface |
||
| 18 | { |
||
| 19 | use RenderableTrait; |
||
| 20 | |||
| 21 | /** @var RenderBlock */ |
||
| 22 | private $renderBlock; |
||
| 23 | /** @var Block[] */ |
||
| 24 | private $blocks = []; |
||
| 25 | /** @var Block[] */ |
||
| 26 | private $defaultBlocks = []; |
||
| 27 | |||
| 28 | public function __construct(RenderBlock $renderBlock, array $blocksToRender = []) |
||
| 29 | { |
||
| 30 | $this->renderBlock = $renderBlock; |
||
| 31 | |||
| 32 | foreach ($blocksToRender as $id) { |
||
| 33 | $this->defaultBlocks[] = new Block($id); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | public function mutate(Handler $ajax): Handler |
||
| 38 | { |
||
| 39 | foreach ($this->getBlocks() as $block) { |
||
| 40 | try { |
||
| 41 | $blockId = str_replace('-', '_', $block->getId()); |
||
| 42 | $html = $this->renderBlock->render($this->view, $blockId, $this->parameters); |
||
| 43 | $ajax->container(sprintf('#%s', $block->getId()))->html($html); |
||
| 44 | } catch (AjaxcomException $exception) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | return $ajax; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function add(string $id): self |
||
| 53 | { |
||
| 54 | $this->blocks[] = new Block($id); |
||
| 55 | |||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return Block[] |
||
| 61 | */ |
||
| 62 | private function getBlocks(): array |
||
| 65 | } |
||
| 66 | } |
||
| 67 |