1
|
|
|
<?php |
2
|
|
|
namespace AlgoWeb\xsdTypes; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* The type xsd:language represents a natural language identifier, generally used to indicate the language of a |
6
|
|
|
* document or a part of a document. Before creating a new attribute of type xsd:language, consider using the xml:lang |
7
|
|
|
* attribute that is intended to indicate the natural language of the element and its content. |
8
|
|
|
* |
9
|
|
|
* Values of the xsd:language type conform to RFC 3066, Tags for the Identification of Languages. |
10
|
|
|
* The three most common formats are: |
11
|
|
|
* |
12
|
|
|
* For ISO-recognized languages, the format is a two- or three-letter, (usually lowercase) language code that |
13
|
|
|
* conforms to ISO 639, optionally followed by a hyphen and a two-letter, (usually uppercase) country code that |
14
|
|
|
* conforms to ISO 3166. For example, en or en-US. |
15
|
|
|
* |
16
|
|
|
* For languages registered by the Internet Assigned Numbers Authority (IANA), the format is i-langname, where |
17
|
|
|
* langname is the registered name. For example, i-navajo. |
18
|
|
|
* |
19
|
|
|
* For unofficial languages, the format is x-langname, where langname is a name of up to eight characters |
20
|
|
|
* agreed upon by the two parties sharing the document. For example, x-Newspeak. |
21
|
|
|
* |
22
|
|
|
* Any of these three formats may have additional parts, each preceded by a hyphen, which identify additional |
23
|
|
|
* countries or dialects. Schema processors will not verify that values of the xsd:language type conform to the above |
24
|
|
|
* rules. They will simply validate based on the pattern specified for this type. |
25
|
|
|
* |
26
|
|
|
* @package AlgoWeb\xsdTypes |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
class xsLanguage extends xsToken |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Construct. |
32
|
|
|
* |
33
|
|
|
* @param string $value |
34
|
|
|
*/ |
35
|
|
|
public function __construct($value) |
36
|
|
|
{ |
37
|
|
|
parent::__construct($value); |
38
|
|
|
/* |
39
|
|
|
* Match a single character present in the list below [a-zA-Z]{1,8} |
40
|
|
|
* {1,8} Quantifier — Matches between 1 and 8 times, as many times as possible, giving back as needed |
41
|
|
|
* a-z a single character in the range between a (index 97) and z (index 122) (case sensitive) |
42
|
|
|
* A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive) |
43
|
|
|
* 1st Capturing Group (-[a-zA-Z0-9]{1,8})* |
44
|
|
|
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed |
45
|
|
|
* A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated |
46
|
|
|
* group to capture all iterations or use a non-capturing group instead if you're not interested in the data |
47
|
|
|
* - matches the character - literally (case sensitive) |
48
|
|
|
* Match a single character present in the list below [a-zA-Z0-9]{1,8} |
49
|
|
|
* {1,8} Quantifier — Matches between 1 and 8 times, as many times as possible, giving back as needed |
50
|
|
|
* a-z a single character in the range between a (index 97) and z (index 122) (case sensitive) |
51
|
|
|
* A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive) |
52
|
|
|
* 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive) |
53
|
|
|
*/ |
54
|
|
|
$this->setPatternFacet('[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*'); |
55
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function fixValue() |
59
|
|
|
{ |
60
|
|
|
parent::fixValue(); |
61
|
|
|
|
62
|
|
|
$this->value = trim($this->value); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function isOK() |
66
|
|
|
{ |
67
|
|
|
parent::isOK(); |
68
|
|
|
if (empty(trim($this->value))) { |
69
|
|
|
throw new \InvalidArgumentException( |
70
|
|
|
'The provided value for ' . __CLASS__ . ' must not be a blank string.' |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|