forked from z38/swiss-payment
-
Notifications
You must be signed in to change notification settings - Fork 6
/
BIC.php
56 lines (47 loc) · 1.1 KB
/
BIC.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
<?php
namespace Z38\SwissPayment;
use DOMDocument;
use InvalidArgumentException;
/**
* BIC
*/
class BIC implements FinancialInstitutionInterface
{
private const PATTERN = '/^[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}$/';
/**
* @var string
*/
protected $bic;
/**
* Constructor
*
* @param string $bic
*
* @throws InvalidArgumentException When the BIC does contain invalid characters or the length does not match.
*/
public function __construct($bic)
{
if (!preg_match(self::PATTERN, $bic)) {
throw new InvalidArgumentException('BIC is not properly formatted.');
}
$this->bic = $bic;
}
/**
* Returns a formatted representation of the BIC
*
* @return string The formatted BIC
*/
public function format()
{
return $this->bic;
}
/**
* {@inheritdoc}
*/
public function asDom(DOMDocument $doc)
{
$xml = $doc->createElement('FinInstnId');
$xml->appendChild($doc->createElement('BIC', $this->format()));
return $xml;
}
}