1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of byrokrat\giroapp. |
4
|
|
|
* |
5
|
|
|
* byrokrat\giroapp is free software: you can redistribute it and/or |
6
|
|
|
* modify it under the terms of the GNU General Public License as published |
7
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* byrokrat\giroapp is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
* |
18
|
|
|
* Copyright 2016-20 Hannes Forsgård |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types = 1); |
22
|
|
|
|
23
|
|
|
namespace byrokrat\giroapp\Formatter; |
24
|
|
|
|
25
|
|
|
use byrokrat\giroapp\Domain\Donor; |
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Output donors in a human readable manner |
30
|
|
|
*/ |
31
|
|
|
final class MailStringFormatter implements FormatterInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var OutputInterface |
35
|
|
|
*/ |
36
|
|
|
private $output; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array<string> |
40
|
|
|
*/ |
41
|
|
|
private $addresses = []; |
42
|
|
|
|
43
|
|
|
public function getName(): string |
44
|
|
|
{ |
45
|
|
|
return 'mailstr'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function initialize(OutputInterface $output): void |
49
|
|
|
{ |
50
|
|
|
$this->output = $output; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function formatDonor(Donor $donor): void |
54
|
|
|
{ |
55
|
|
|
if (!$donor->getEmail()) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!$donor->getName()) { |
60
|
|
|
$this->addresses[] = $donor->getEmail(); |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->addresses[] = sprintf( |
65
|
|
|
'%s <%s>', |
66
|
|
|
$donor->getName(), |
67
|
|
|
$donor->getEmail() |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function finalize(): void |
72
|
|
|
{ |
73
|
|
|
$this->output->writeln(implode(', ', $this->addresses)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|