Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockRenderer.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  const CODE = 'block_renderer';
17 
21  private $configuration;
22 
26  private $template;
27 
31  public function __construct(
32  Template $template
33  ) {
34  $this->template = $template;
35  }
36 
44  public function render(MessageInterface $message, array $initializationData)
45  {
46  $this->setUpConfiguration($message->getData(), $initializationData);
47 
48  $result = $this->template->toHtml();
49 
50  $this->tearDownConfiguration();
51 
52  return $result;
53  }
54 
60  private function setUpConfiguration(array $configuration, array $initializationData)
61  {
62  if (!isset($initializationData['template'])) {
63  throw new \InvalidArgumentException('Template should be provided for the renderer.');
64  }
65 
66  $this->configuration = $configuration;
67 
68  $this->template->setTemplate($initializationData['template']);
69  $this->template->setData($configuration);
70  }
71 
75  private function tearDownConfiguration()
76  {
77  foreach (array_keys($this->configuration) as $key) {
78  $this->template->unsetData($key);
79  unset($this->configuration[$key]);
80  }
81 
82  $this->template->setTemplate('');
83  }
84 }
$configuration
Definition: index.php:33
$message
render(MessageInterface $message, array $initializationData)