forked from z38/swiss-payment
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGeneralAccount.php
57 lines (48 loc) · 1.16 KB
/
GeneralAccount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Z38\SwissPayment;
use DOMDocument;
use InvalidArgumentException;
/**
* GeneralAccount holds details about an account which is not covered by any of the other classes
*/
class GeneralAccount implements AccountInterface
{
const MAX_LENGTH = 34;
/**
* @var string
*/
protected $id;
/**
* Constructor
*
* @param string $id
*
* @throws InvalidArgumentException When the account identification exceeds the maximum length.
*/
public function __construct($id)
{
$stringId = (string) $id;
if (strlen($stringId) > self::MAX_LENGTH) {
throw new InvalidArgumentException('The account identifcation is too long.');
}
$this->id = $stringId;
}
/**
* {@inheritdoc}
*/
public function format()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function asDom(DOMDocument $doc)
{
$root = $doc->createElement('Id');
$other = $doc->createElement('Othr');
$other->appendChild($doc->createElement('Id', $this->format()));
$root->appendChild($other);
return $root;
}
}