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
|
|
|
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
|
|
|
$this->setPatternFacet("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*"); |
39
|
|
|
$this->setWhiteSpaceFacet("collapse"); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function fixValue() |
43
|
|
|
{ |
44
|
|
|
parent::fixValue(); |
45
|
|
|
|
46
|
|
|
$this->value = trim($this->value); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function isOK() |
50
|
|
|
{ |
51
|
|
|
parent::isOK(); |
52
|
|
|
if (empty(trim($this->value))) { |
53
|
|
|
throw new \InvalidArgumentException( |
54
|
|
|
"The provided value for " . __CLASS__ . " must not be a blank string." |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
if (8 < strlen($this->value)) { |
58
|
|
|
throw new \InvalidArgumentException( |
59
|
|
|
"The provided value for " . __CLASS__ . " must not be longer than 8 characters." |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|