1 | <?php |
||
16 | class RDN implements |
||
17 | \Countable, \IteratorAggregate |
||
18 | { |
||
19 | /** |
||
20 | * Attributes. |
||
21 | * |
||
22 | * @var AttributeTypeAndValue[] $_attribs |
||
23 | */ |
||
24 | protected $_attribs; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * |
||
29 | * @param AttributeTypeAndValue ...$attribs One or more attributes |
||
30 | */ |
||
31 | 39 | public function __construct(AttributeTypeAndValue ...$attribs) { |
|
32 | 39 | if (!count($attribs)) { |
|
33 | 1 | throw new \UnexpectedValueException( |
|
34 | 1 | "RDN must have at least one AttributeTypeAndValue."); |
|
35 | } |
||
36 | 38 | $this->_attribs = $attribs; |
|
37 | 38 | } |
|
38 | |||
39 | /** |
||
40 | * Convenience method to initialize RDN from AttributeValue objects. |
||
41 | * |
||
42 | * @param AttributeValue ...$values One or more attributes |
||
43 | * @return self |
||
44 | */ |
||
45 | 4 | public static function fromAttributeValues(AttributeValue ...$values) { |
|
46 | 1 | $attribs = array_map( |
|
47 | function (AttributeValue $value) { |
||
48 | 1 | return new AttributeTypeAndValue( |
|
49 | 1 | new AttributeType($value->oid()), $value); |
|
50 | 1 | }, $values); |
|
51 | 1 | return new self(...$attribs); |
|
52 | 4 | } |
|
53 | |||
54 | /** |
||
55 | * Initialize from ASN.1. |
||
56 | * |
||
57 | * @param Set $set |
||
58 | * @return self |
||
59 | */ |
||
60 | 4 | public static function fromASN1(Set $set) { |
|
61 | 4 | $attribs = array_map( |
|
62 | function (UnspecifiedType $el) { |
||
63 | 4 | return AttributeTypeAndValue::fromASN1($el->asSequence()); |
|
64 | 4 | }, $set->elements()); |
|
65 | 4 | return new self(...$attribs); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Generate ASN.1 structure. |
||
70 | * |
||
71 | * @return Set |
||
72 | */ |
||
73 | 4 | public function toASN1() { |
|
81 | |||
82 | /** |
||
83 | * Get name-component string conforming to RFC 2253. |
||
84 | * |
||
85 | * @link https://tools.ietf.org/html/rfc2253#section-2.2 |
||
86 | * @return string |
||
87 | */ |
||
88 | 15 | public function toString() { |
|
95 | |||
96 | /** |
||
97 | * Check whether RDN is semantically equal to other. |
||
98 | * |
||
99 | * @param RDN $other Object to compare to |
||
100 | * @return bool |
||
101 | */ |
||
102 | 22 | public function equals(RDN $other) { |
|
123 | |||
124 | /** |
||
125 | * Get all AttributeTypeAndValue objects. |
||
126 | * |
||
127 | * @return AttributeTypeAndValue[] |
||
128 | */ |
||
129 | 1 | public function all() { |
|
132 | |||
133 | /** |
||
134 | * |
||
135 | * @see Countable::count() |
||
136 | * @return int |
||
137 | */ |
||
138 | 23 | public function count() { |
|
141 | |||
142 | /** |
||
143 | * |
||
144 | * @see IteratorAggregate::getIterator() |
||
145 | * @return \ArrayIterator |
||
146 | */ |
||
147 | 1 | public function getIterator() { |
|
150 | |||
151 | /** |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 1 | public function __toString() { |
|
158 | } |
||
159 |