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 | 5 | public function __construct(TemplateProviderInterface $templateProvider, TranslatorInterface $translator){ |
|
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 1 | public function getFilters() |
|
34 | |||
35 | 1 | public function urlEncodeText($text) |
|
59 | |||
60 | /** |
||
61 | * Wrap the text to the lineLength is not exeeded. |
||
62 | * @param string $text |
||
63 | * @param integer $lineLength default: 75 |
||
64 | * @return string the wrapped string |
||
65 | */ |
||
66 | 3 | public function textWrap($text, $lineLength = 75) |
|
70 | |||
71 | /** |
||
72 | * Returns the name of the extension. |
||
73 | * |
||
74 | * @return string The extension name |
||
75 | */ |
||
76 | 1 | public function getName() |
|
80 | |||
81 | public function addCampaignParamsForTemplate($html, $templateId, $templateParams){ |
||
85 | |||
86 | /** |
||
87 | * Add the campaign-parameters to all URLs in the html |
||
88 | * @param string $html |
||
89 | * @param array $campaignParams |
||
90 | * @return string |
||
91 | */ |
||
92 | 7 | public static function addCampaignParamsToAllUrls($html, $campaignParams) |
|
126 | } |
||
127 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.