|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of byrokrat\giroapp. |
|
5
|
|
|
* |
|
6
|
|
|
* byrokrat\giroapp is free software: you can redistribute it and/or |
|
7
|
|
|
* modify it under the terms of the GNU General Public License as published |
|
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* byrokrat\giroapp is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
* |
|
19
|
|
|
* Copyright 2016-21 Hannes Forsgård |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
declare(strict_types=1); |
|
23
|
|
|
|
|
24
|
|
|
namespace byrokrat\giroapp\Xml; |
|
25
|
|
|
|
|
26
|
|
|
use byrokrat\giroapp\Console\ConsoleInterface; |
|
27
|
|
|
use Money\MoneyFormatter; |
|
28
|
|
|
|
|
29
|
|
|
final class HumanDumper implements XmlMandateDumperInterface |
|
30
|
|
|
{ |
|
31
|
|
|
private const COLORING_TAG = 'comment'; |
|
32
|
|
|
|
|
33
|
|
|
/** @var MoneyFormatter */ |
|
34
|
|
|
private $moneyFormatter; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(MoneyFormatter $moneyFormatter) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->moneyFormatter = $moneyFormatter; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private static function color(string $str): string |
|
42
|
|
|
{ |
|
43
|
|
|
return sprintf( |
|
44
|
|
|
'<%s>%s</%s>', |
|
45
|
|
|
self::COLORING_TAG, |
|
46
|
|
|
$str, |
|
47
|
|
|
self::COLORING_TAG |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function dump(XmlMandate $xmlMandate): string |
|
52
|
|
|
{ |
|
53
|
|
|
$attributes = ''; |
|
54
|
|
|
|
|
55
|
|
|
foreach ($xmlMandate->attributes as $attrKey => $attrValue) { |
|
56
|
|
|
$attributes .= "attribute.$attrKey: {$this->color($attrValue)}\n"; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return trim(sprintf( |
|
60
|
|
|
"%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s, %s, %s, %s, %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s", |
|
61
|
|
|
ConsoleInterface::OPTION_DESCS['payer-number'], |
|
62
|
|
|
self::color($xmlMandate->payerNumber), |
|
63
|
|
|
ConsoleInterface::OPTION_DESCS['account'], |
|
64
|
|
|
self::color($xmlMandate->account->prettyprint()), |
|
65
|
|
|
ConsoleInterface::OPTION_DESCS['id'], |
|
66
|
|
|
self::color($xmlMandate->donorId->format('CS-sk')), |
|
67
|
|
|
ConsoleInterface::OPTION_DESCS['name'], |
|
68
|
|
|
self::color($xmlMandate->name), |
|
69
|
|
|
ConsoleInterface::OPTION_DESCS['address'], |
|
70
|
|
|
self::color($xmlMandate->address['line1']), |
|
71
|
|
|
self::color($xmlMandate->address['line2']), |
|
72
|
|
|
self::color($xmlMandate->address['line3']), |
|
73
|
|
|
self::color($xmlMandate->address['postalCode']), |
|
74
|
|
|
self::color($xmlMandate->address['postalCity']), |
|
75
|
|
|
ConsoleInterface::OPTION_DESCS['email'], |
|
76
|
|
|
self::color($xmlMandate->email), |
|
77
|
|
|
ConsoleInterface::OPTION_DESCS['phone'], |
|
78
|
|
|
self::color($xmlMandate->phone), |
|
79
|
|
|
ConsoleInterface::OPTION_DESCS['amount'], |
|
80
|
|
|
self::color($this->moneyFormatter->format($xmlMandate->donationAmount)), |
|
81
|
|
|
ConsoleInterface::OPTION_DESCS['comment'], |
|
82
|
|
|
self::color($xmlMandate->comment), |
|
83
|
|
|
$attributes |
|
84
|
|
|
)); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|