| @@ 21-48 (lines=28) @@ | ||
| 18 | * whitespace in between the necessary characters and the equals sign(s). |
|
| 19 | * @package AlgoWeb\xsdTypes |
|
| 20 | */ |
|
| 21 | 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 | ||
| @@ 13-40 (lines=28) @@ | ||
| 10 | * For example, 0FB8 and 0fb8 are two equal xsd:hexBinary representations consisting of two octets. |
|
| 11 | * @package AlgoWeb\xsdTypes |
|
| 12 | */ |
|
| 13 | class xsHexBinary extends xsAnySimpleType |
|
| 14 | { |
|
| 15 | use LengthTrait; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Construct. |
|
| 19 | * |
|
| 20 | * @param string $value |
|
| 21 | */ |
|
| 22 | public function __construct($value) |
|
| 23 | { |
|
| 24 | parent::__construct($value); |
|
| 25 | $this->setWhiteSpaceFacet('collapse'); |
|
| 26 | } |
|
| 27 | ||
| 28 | protected function isOK() |
|
| 29 | { |
|
| 30 | $this->checkLength($this->value); |
|
| 31 | $lengthOfValue = strlen($this->value); |
|
| 32 | if ($lengthOfValue % 2 != 0) { |
|
| 33 | throw new \InvalidArgumentException('the value ' . $this->value . 'is not valid; characters must appear' . |
|
| 34 | 'in pairs'); |
|
| 35 | } |
|
| 36 | if (!ctype_xdigit($this->value)) { |
|
| 37 | throw new \InvalidArgumentException('the value ' . $this->value . 'contains invalid characters'); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||