1 | <?php |
||
21 | class Name implements \Countable, \IteratorAggregate |
||
22 | { |
||
23 | /** |
||
24 | * Relative distinguished name components. |
||
25 | * |
||
26 | * @var RDN[] $_rdns |
||
27 | */ |
||
28 | protected $_rdns; |
||
29 | |||
30 | /** |
||
31 | * Constructor |
||
32 | * |
||
33 | * @param RDN ...$rdns RDN components |
||
34 | */ |
||
35 | 37 | public function __construct(RDN ...$rdns) { |
|
38 | |||
39 | /** |
||
40 | * Initialize from ASN.1. |
||
41 | * |
||
42 | * @param Sequence $seq |
||
43 | * @return self |
||
44 | */ |
||
45 | 1 | public static function fromASN1(Sequence $seq) { |
|
52 | |||
53 | /** |
||
54 | * Initialize from distinguished name string. |
||
55 | * |
||
56 | * @link https://tools.ietf.org/html/rfc1779 |
||
57 | * @param string $str |
||
58 | * @return self |
||
59 | */ |
||
60 | 36 | public static function fromString($str) { |
|
80 | |||
81 | /** |
||
82 | * Generate ASN.1 structure. |
||
83 | * |
||
84 | * @return Sequence |
||
85 | */ |
||
86 | 1 | public function toASN1() { |
|
93 | |||
94 | /** |
||
95 | * Get distinguised name string conforming to RFC 2253. |
||
96 | * |
||
97 | * @link https://tools.ietf.org/html/rfc2253#section-2.1 |
||
98 | * @return string |
||
99 | */ |
||
100 | 13 | public function toString() { |
|
101 | 13 | $parts = array_map( |
|
102 | function (RDN $rdn) { |
||
103 | 13 | return $rdn->toString(); |
|
104 | 13 | }, array_reverse($this->_rdns)); |
|
105 | 13 | return implode(",", $parts); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Whether name is semantically equal to other. |
||
110 | * Comparison conforms to RFC 4518 string preparation algorithm. |
||
111 | * |
||
112 | * @link https://tools.ietf.org/html/rfc4518 |
||
113 | * @param Name $other Object to compare to |
||
114 | * @return bool |
||
115 | */ |
||
116 | 23 | public function equals(Name $other) { |
|
130 | |||
131 | /** |
||
132 | * Get all RDN objects. |
||
133 | * |
||
134 | * @return RDN[] |
||
135 | */ |
||
136 | 1 | public function all() { |
|
139 | |||
140 | /** |
||
141 | * Get the first AttributeValue of given type. |
||
142 | * |
||
143 | * Relative name components shall be traversed in encoding order, which is |
||
144 | * reversed in regards to the string representation. |
||
145 | * Multi-valued RDN with multiple attributes of the requested type is |
||
146 | * ambiguous and shall throw an exception. |
||
147 | * |
||
148 | * @param string $name Attribute OID or name |
||
149 | * @throws \RuntimeException If attribute cannot be resolved |
||
150 | * @return AttributeValue |
||
151 | */ |
||
152 | 3 | public function firstValueOf($name) { |
|
165 | |||
166 | /** |
||
167 | * |
||
168 | * @see Countable::count() |
||
169 | * @return int |
||
170 | */ |
||
171 | 24 | public function count() { |
|
174 | |||
175 | /** |
||
176 | * Get the number of attributes of given type. |
||
177 | * |
||
178 | * @param string $name Attribute OID or name |
||
179 | * @return int |
||
180 | */ |
||
181 | 2 | public function countOfType($name) { |
|
189 | |||
190 | /** |
||
191 | * |
||
192 | * @see IteratorAggregate::getIterator() |
||
193 | * @return \ArrayIterator |
||
194 | */ |
||
195 | 1 | public function getIterator() { |
|
198 | |||
199 | /** |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | 1 | public function __toString() { |
|
206 | } |
||
207 |