These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Azine\EmailBundle\Services; |
||
4 | |||
5 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
||
6 | |||
7 | /** |
||
8 | * You must override this service for your needs. Also see ExampleAzineWebViewSerive for some examples. |
||
9 | * |
||
10 | * @author dominik |
||
11 | */ |
||
12 | class AzineWebViewService implements WebViewServiceInterface |
||
13 | { |
||
14 | /** |
||
15 | * (non-PHPdoc). |
||
16 | * |
||
17 | * @see Azine\EmailBundle\Services.WebViewServiceInterface::getTemplatesForWebPreView() |
||
18 | */ |
||
19 | 1 | View Code Duplication | public function getTemplatesForWebPreView() |
0 ignored issues
–
show
|
|||
20 | { |
||
21 | 1 | $templates = array(); |
|
22 | 1 | $templates = $this->addTemplate($templates, 'Reset Passwort Email', AzineTemplateProvider::FOS_USER_PWD_RESETTING_TEMPLATE); |
|
23 | 1 | $templates = $this->addTemplate($templates, 'Account activation', AzineTemplateProvider::FOS_USER_REGISTRATION_TEMPLATE); |
|
24 | // override this method to add your own templates |
||
25 | // $templates =$this->addTemplate($templates, "Some other mail", ExampleTemplateProvider::SOME_OTHER_MAIL_TEMPLATE); |
||
26 | // $templates =$this->addTemplate($templates, "VIP Infos", ExampleTemplateProvider::VIP_INFO_MAIL_TEMPLATE); |
||
27 | 1 | return $templates; |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * (non-PHPdoc). |
||
32 | * |
||
33 | * @see Azine\EmailBundle\Services.WebViewServiceInterface::getTestMailAccounts() |
||
34 | */ |
||
35 | 1 | public function getTestMailAccounts() |
|
36 | { |
||
37 | 1 | $emails = array(); |
|
38 | // override this method to add your own emails |
||
39 | // $emails = $this->addTestMailAccount($emails, 'Testmail-account for MS Outlook', '[email protected]'); |
||
40 | // $emails = $this->addTestMailAccount($emails, 'Testmail-account for Gmail', 'your.email.address@gmail'); |
||
41 | 1 | return $emails; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * (non-PHPdoc). |
||
46 | * |
||
47 | * @see Azine\EmailBundle\Services.WebViewServiceInterface::getDummyVarsFor() |
||
48 | */ |
||
49 | 1 | public function getDummyVarsFor($template, $locale, $variables = array()) |
|
50 | { |
||
51 | 1 | $variables['subject'] = 'some dummy subject'; |
|
52 | 1 | $variables['sendMailAccountName'] = 'some name'; |
|
53 | 1 | $variables['sendMailAccountAddress'] = '[email protected]'; |
|
54 | |||
55 | // override this method to provide dummy-variables |
||
56 | // to view rendered templates for emails that you didn't send yet |
||
57 | // or to send an email with dummy-variables to your test-account(s) |
||
58 | // |
||
59 | // do something like this: |
||
60 | // |
||
61 | // if ($template == ExampleTemplateProvider::VIP_INFO_MAIL_TEMPLATE) { |
||
62 | // $vipVars = array(); |
||
63 | // $vipVars['vipInfos'] = $someService->getVipInfosFor($aUser); |
||
64 | // $vipVars['userTitle'] = "You majesty"; |
||
65 | // $variables['contentItems'][] = array(ExampleTemplateProvider::VIP_INFO_MAIL_TEMPLATE, $vipVars); |
||
66 | |||
67 | // } elseif ($template == ExampleTemplateProvider::SOME_OTHER_MAIL_TEMPLATE) { |
||
68 | // $otherMailVars = array(); |
||
69 | // $otherMailVars['date'] = new \DateTime("long ago"); |
||
70 | // $variables['contentItems'][] = array(ExampleTemplateProvider::SOME_OTHER_MAIL_TEMPLATE, $otherMailVars); |
||
71 | // } |
||
72 | 1 | return $variables; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param UrlGeneratorInterface $router |
||
77 | */ |
||
78 | 5 | public function __construct(UrlGeneratorInterface $router) |
|
79 | { |
||
80 | 5 | $this->router = $router; |
|
81 | 5 | } |
|
82 | |||
83 | ////////////////////////////////////////////////////////////////////////// |
||
84 | /* You probably don't need to change or override any of the stuff below */ |
||
85 | ////////////////////////////////////////////////////////////////////////// |
||
86 | |||
87 | /** |
||
88 | * @var UrlGeneratorInterface |
||
89 | */ |
||
90 | protected $router; |
||
91 | |||
92 | /** |
||
93 | * Add an email of a test account, you might want to send html-emails to, to verify the template before sending the emails to "real" recipients/users. |
||
94 | * |
||
95 | * @param array $emails |
||
96 | * @param string $description |
||
97 | * @param string $emailAddress |
||
98 | * |
||
99 | * @return array the array with the added email-test-account |
||
100 | */ |
||
101 | 1 | protected function addTestMailAccount(array $emails, $description, $emailAddress) |
|
102 | { |
||
103 | 1 | $emails[] = array('accountDescription' => $description, 'accountEmail' => $emailAddress); |
|
104 | |||
105 | 1 | return $emails; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Add the required variables to the $templates-array, so the line can be rendered in the template-index. |
||
110 | * |
||
111 | * @param array $templates |
||
112 | * @param string $description |
||
113 | * @param string $templateId |
||
114 | * @param array $formats |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | 2 | protected function addTemplate($templates, $description, $templateId, $formats = array('txt', 'html')) |
|
119 | { |
||
120 | 2 | $route = $this->router->generate('azine_email_web_preview', array('template' => urlencode($templateId))); |
|
121 | |||
122 | 2 | $template = array('url' => $route, |
|
123 | 2 | 'description' => $description, |
|
124 | 2 | 'formats' => $formats, |
|
125 | 2 | 'templateId' => $templateId, |
|
126 | ); |
||
127 | |||
128 | 2 | $templates[] = $template; |
|
129 | |||
130 | 2 | return $templates; |
|
131 | } |
||
132 | } |
||
133 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.