1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element\Message\Renderer;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\View\Element\Message\Renderer\BlockRenderer\Template;
class BlockRenderer implements RendererInterface
{
/**
* complex_renderer
*/
const CODE = 'block_renderer';
/**
* @var array
*/
private $configuration;
/**
* @var Template
*/
private $template;
/**
* @param Template $template
*/
public function __construct(
Template $template
) {
$this->template = $template;
}
/**
* Renders complex message
*
* @param MessageInterface $message
* @param array $initializationData
* @return string
*/
public function render(MessageInterface $message, array $initializationData)
{
$this->setUpConfiguration($message->getData(), $initializationData);
$result = $this->template->toHtml();
$this->tearDownConfiguration();
return $result;
}
/**
* @param array $configuration
* @param array $initializationData
* @return void
*/
private function setUpConfiguration(array $configuration, array $initializationData)
{
if (!isset($initializationData['template'])) {
throw new \InvalidArgumentException('Template should be provided for the renderer.');
}
$this->configuration = $configuration;
$this->template->setTemplate($initializationData['template']);
$this->template->setData($configuration);
}
/**
* @return void
*/
private function tearDownConfiguration()
{
foreach (array_keys($this->configuration) as $key) {
$this->template->unsetData($key);
unset($this->configuration[$key]);
}
$this->template->setTemplate('');
}
}