1 | <?php |
||
21 | class Attributes implements \Countable, \IteratorAggregate |
||
22 | { |
||
23 | use AttributeContainer; |
||
24 | |||
25 | /** |
||
26 | * Mapping from OID to attribute value class name. |
||
27 | * |
||
28 | * @internal |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | const MAP_OID_TO_CLASS = [ |
||
33 | ExtensionRequestValue::OID => ExtensionRequestValue::class, |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | * |
||
39 | * @param Attribute ...$attribs Attribute objects |
||
40 | */ |
||
41 | 8 | public function __construct(Attribute ...$attribs) |
|
42 | { |
||
43 | 8 | $this->_attributes = $attribs; |
|
44 | 8 | } |
|
45 | |||
46 | /** |
||
47 | * Initialize from attribute values. |
||
48 | * |
||
49 | * @param AttributeValue ...$values |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | 1 | public static function fromAttributeValues(AttributeValue ...$values): Attributes |
|
54 | { |
||
55 | 1 | $attribs = array_map( |
|
56 | function (AttributeValue $value) { |
||
57 | 1 | return $value->toAttribute(); |
|
58 | 1 | }, $values); |
|
59 | 1 | return new self(...$attribs); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Initialize from ASN.1. |
||
64 | * |
||
65 | * @param Set $set |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | 4 | public static function fromASN1(Set $set): Attributes |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Check whether extension request attribute is present. |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 6 | public function hasExtensionRequest(): bool |
|
94 | { |
||
95 | 6 | return $this->has(ExtensionRequestValue::OID); |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get extension request attribute value. |
||
100 | * |
||
101 | * @throws \LogicException |
||
102 | * |
||
103 | * @return ExtensionRequestValue |
||
104 | */ |
||
105 | 4 | public function extensionRequest(): ExtensionRequestValue |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * Generate ASN.1 structure. |
||
115 | * |
||
116 | * @return Set |
||
117 | */ |
||
118 | 5 | public function toASN1(): Set |
|
126 | } |
||
127 | } |
||
128 |