1 | <?php |
||
6 | class AzineEmailTwigExtension extends \Twig_Extension |
||
7 | { |
||
8 | /** |
||
9 | * @var TemplateProviderInterface |
||
10 | */ |
||
11 | private $templateProvider; |
||
12 | |||
13 | /** |
||
14 | * @var TranslatorInterface |
||
15 | */ |
||
16 | private $translator; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $domainsToTrack; |
||
22 | |||
23 | /** |
||
24 | * @param TemplateProviderInterface $templateProvider |
||
25 | * @param array of string $domainsToTrack |
||
26 | */ |
||
27 | 11 | public function __construct(TemplateProviderInterface $templateProvider, TranslatorInterface $translator, array $domainsToTrack = array()){ |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 1 | public function getFilters() |
|
44 | |||
45 | 1 | public function urlEncodeText($text) |
|
69 | |||
70 | /** |
||
71 | * Wrap the text to the lineLength is not exeeded. |
||
72 | * @param string $text |
||
73 | * @param integer $lineLength default: 75 |
||
74 | * @return string the wrapped string |
||
75 | */ |
||
76 | 3 | public function textWrap($text, $lineLength = 75) |
|
80 | |||
81 | /** |
||
82 | * Returns the name of the extension. |
||
83 | * |
||
84 | * @return string The extension name |
||
85 | */ |
||
86 | 1 | public function getName() |
|
90 | |||
91 | public function addCampaignParamsForTemplate($html, $templateId, $templateParams){ |
||
95 | |||
96 | /** |
||
97 | * Add the campaign-parameters to all URLs in the html |
||
98 | * @param string $html |
||
99 | * @param array $campaignParams |
||
100 | * @return string |
||
101 | */ |
||
102 | 3 | public function addCampaignParamsToAllUrls($html, $campaignParams) |
|
143 | |||
144 | /** |
||
145 | * Convert: |
||
146 | * - a-tags to show the link and if the link-text is not contained in the link, also the link-text |
||
147 | * - remove double-whitespaces and whitespaces at line beginnings and ends. |
||
148 | * - html-special chars to their original representation (php => htmlspecialchars_decode) |
||
149 | * and then remove all html-tags (php => strip_tags) |
||
150 | */ |
||
151 | 1 | public function stripAndConvertTags($html){ |
|
174 | } |
||
175 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.