1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\xsdTypes\Facets\LengthTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* The type xsd:base64Binary represents binary data as a sequence of binary octets. It uses base64 encoding, as |
9
|
|
|
* described in RFC 2045. The following rules apply to xsd:base64Binary values:. |
10
|
|
|
* |
11
|
|
|
* - The following characters are allowed: the letters A to Z (upper and lower case), digits 0 through 9, the plus sign |
12
|
|
|
* ("+"), the slash ("/"), the equals sign ("=") and XML whitespace characters. |
13
|
|
|
* - XML whitespace characters may appear anywhere in the value. |
14
|
|
|
* - The number of non-whitespace characters must be divisible by 4. |
15
|
|
|
* - Equals signs may only appear at the end of the value, and there may be zero, one or two of them. If there are two |
16
|
|
|
* equals signs, they must be preceded by one of the following characters: AQgw. If there is only one equals sign, |
17
|
|
|
* it must be preceded by one of the following characters: AEIMQUYcgkosw048. In either case, there may be |
18
|
|
|
* whitespace in between the necessary characters and the equals sign(s). |
19
|
|
|
* @package AlgoWeb\xsdTypes |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class xsBase64Binary extends xsAnySimpleType |
22
|
|
|
{ |
23
|
|
|
use LengthTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Construct. |
27
|
|
|
* |
28
|
|
|
* @param string $value |
29
|
|
|
*/ |
30
|
|
|
public function __construct($value) |
31
|
|
|
{ |
32
|
|
|
parent::__construct($value); |
33
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function isOK() |
37
|
|
|
{ |
38
|
|
|
$this->checkLength($this->value); |
39
|
|
|
if (!(bool)preg_match('/^[a-zA-Z0-9\/\r\n+\s]*={0,2}$/', $this->value)) { |
40
|
|
|
throw new \InvalidArgumentException('the value ' . $this->value . ' is not a valid base64 encoded string'); |
41
|
|
|
} |
42
|
|
|
$lengthOfValue = strlen($this->value); |
43
|
|
|
if ($lengthOfValue % 2 != 0) { |
44
|
|
|
throw new \InvalidArgumentException('the value ' . $this->value . ' is not a valid base64 encoded string' . |
45
|
|
|
'as it dose not contain an even number of characters'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|