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\Xml; |
24
|
|
|
|
25
|
|
|
use byrokrat\giroapp\Console\ConsoleInterface; |
26
|
|
|
use Money\MoneyFormatter; |
27
|
|
|
|
28
|
|
|
final class HumanDumper implements XmlMandateDumperInterface |
29
|
|
|
{ |
30
|
|
|
private const COLORING_TAG = 'comment'; |
31
|
|
|
|
32
|
|
|
/** @var MoneyFormatter */ |
33
|
|
|
private $moneyFormatter; |
34
|
|
|
|
35
|
|
|
public function __construct(MoneyFormatter $moneyFormatter) |
36
|
|
|
{ |
37
|
|
|
$this->moneyFormatter = $moneyFormatter; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private static function color(string $str): string |
41
|
|
|
{ |
42
|
|
|
return sprintf( |
43
|
|
|
'<%s>%s</%s>', |
44
|
|
|
self::COLORING_TAG, |
45
|
|
|
$str, |
46
|
|
|
self::COLORING_TAG |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function dump(XmlMandate $xmlMandate): string |
51
|
|
|
{ |
52
|
|
|
$attributes = ''; |
53
|
|
|
|
54
|
|
|
foreach ($xmlMandate->attributes as $attrKey => $attrValue) { |
55
|
|
|
$attributes .= "attribute.$attrKey: {$this->color($attrValue)}\n"; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return trim(sprintf( |
59
|
|
|
"%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", |
60
|
|
|
ConsoleInterface::OPTION_DESCS['payer-number'], |
61
|
|
|
self::color($xmlMandate->payerNumber), |
62
|
|
|
ConsoleInterface::OPTION_DESCS['account'], |
63
|
|
|
self::color($xmlMandate->account->prettyprint()), |
64
|
|
|
ConsoleInterface::OPTION_DESCS['id'], |
65
|
|
|
self::color($xmlMandate->donorId->format('CS-sk')), |
66
|
|
|
ConsoleInterface::OPTION_DESCS['name'], |
67
|
|
|
self::color($xmlMandate->name), |
68
|
|
|
ConsoleInterface::OPTION_DESCS['address'], |
69
|
|
|
self::color($xmlMandate->address['line1']), |
70
|
|
|
self::color($xmlMandate->address['line2']), |
71
|
|
|
self::color($xmlMandate->address['line3']), |
72
|
|
|
self::color($xmlMandate->address['postalCode']), |
73
|
|
|
self::color($xmlMandate->address['postalCity']), |
74
|
|
|
ConsoleInterface::OPTION_DESCS['email'], |
75
|
|
|
self::color($xmlMandate->email), |
76
|
|
|
ConsoleInterface::OPTION_DESCS['phone'], |
77
|
|
|
self::color($xmlMandate->phone), |
78
|
|
|
ConsoleInterface::OPTION_DESCS['amount'], |
79
|
|
|
self::color($this->moneyFormatter->format($xmlMandate->donationAmount)), |
80
|
|
|
ConsoleInterface::OPTION_DESCS['comment'], |
81
|
|
|
self::color($xmlMandate->comment), |
82
|
|
|
$attributes |
83
|
|
|
)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|