|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ManagementBundle\Configuration\Service; |
|
20
|
|
|
|
|
21
|
|
|
use Exception; |
|
22
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Dto\EmailTemplate; |
|
23
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Service\EmailTemplateService as CommandHandlingEmailTemplateService; |
|
|
|
|
|
|
24
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Exception\RuntimeException; |
|
25
|
|
|
use Surfnet\StepupMiddleware\ManagementBundle\Configuration\Repository\EmailTemplateRepository; |
|
26
|
|
|
|
|
27
|
|
|
final class EmailTemplateService implements CommandHandlingEmailTemplateService |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var \Surfnet\StepupMiddleware\ManagementBundle\Configuration\Repository\EmailTemplateRepository |
|
31
|
|
|
*/ |
|
32
|
|
|
private $repository; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct( |
|
35
|
|
|
EmailTemplateRepository $repository |
|
36
|
|
|
) { |
|
37
|
|
|
$this->repository = $repository; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function findByName($name, $preferredLocale, $fallbackLocale) |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
$emailTemplateEntity = $this->repository->findByName($name, $preferredLocale, $fallbackLocale); |
|
44
|
|
|
} catch (Exception $e) { |
|
45
|
|
|
throw new RuntimeException($e->getMessage(), 0, $e); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$emailTemplate = new EmailTemplate(); |
|
49
|
|
|
$emailTemplate->name = $emailTemplateEntity->getName(); |
|
50
|
|
|
$emailTemplate->locale = $emailTemplateEntity->getLocale(); |
|
51
|
|
|
$emailTemplate->htmlContent = $emailTemplateEntity->getHtmlContent(); |
|
52
|
|
|
|
|
53
|
|
|
return $emailTemplate; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.