| 1 | <?php |
||
| 17 | class UserNoticeQualifier extends PolicyQualifierInfo |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Explicit notice text. |
||
| 21 | * |
||
| 22 | * @var null|DisplayText |
||
| 23 | */ |
||
| 24 | protected $_text; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Notice reference. |
||
| 28 | * |
||
| 29 | * @var null|NoticeReference |
||
| 30 | */ |
||
| 31 | protected $_ref; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Constructor. |
||
| 35 | * |
||
| 36 | * @param null|DisplayText $text |
||
| 37 | * @param null|NoticeReference $ref |
||
| 38 | */ |
||
| 39 | 16 | public function __construct(?DisplayText $text = null, |
|
| 40 | ?NoticeReference $ref = null) |
||
| 41 | { |
||
| 42 | 16 | $this->_oid = self::OID_UNOTICE; |
|
| 43 | 16 | $this->_text = $text; |
|
| 44 | 16 | $this->_ref = $ref; |
|
| 45 | 16 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | * |
||
| 50 | * @return self |
||
| 51 | */ |
||
| 52 | 11 | public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
| 53 | { |
||
| 54 | 11 | $seq = $el->asSequence(); |
|
| 55 | 11 | $ref = null; |
|
| 56 | 11 | $text = null; |
|
| 57 | 11 | $idx = 0; |
|
| 58 | 11 | if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 59 | 10 | $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
| 60 | } |
||
| 61 | 11 | if ($seq->has($idx, Element::TYPE_STRING)) { |
|
| 62 | 11 | $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
| 63 | } |
||
| 64 | 11 | return new self($text, $ref); |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Whether explicit text is present. |
||
| 69 | * |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | 5 | public function hasExplicitText(): bool |
|
| 73 | { |
||
| 74 | 5 | return isset($this->_text); |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Get explicit text. |
||
| 79 | * |
||
| 80 | * @throws \LogicException If not set |
||
| 81 | * |
||
| 82 | * @return DisplayText |
||
| 83 | */ |
||
| 84 | 5 | public function explicitText(): DisplayText |
|
| 85 | { |
||
| 86 | 5 | if (!$this->hasExplicitText()) { |
|
| 87 | 1 | throw new \LogicException('explicitText not set.'); |
|
| 88 | } |
||
| 89 | 4 | return $this->_text; |
|
|
1 ignored issue
–
show
|
|||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Whether notice reference is present. |
||
| 94 | * |
||
| 95 | * @return bool |
||
| 96 | */ |
||
| 97 | 4 | public function hasNoticeRef(): bool |
|
| 98 | { |
||
| 99 | 4 | return isset($this->_ref); |
|
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Get notice reference. |
||
| 104 | * |
||
| 105 | * @throws \LogicException If not set |
||
| 106 | * |
||
| 107 | * @return NoticeReference |
||
| 108 | */ |
||
| 109 | 4 | public function noticeRef(): NoticeReference |
|
| 110 | { |
||
| 111 | 4 | if (!$this->hasNoticeRef()) { |
|
| 112 | 1 | throw new \LogicException('noticeRef not set.'); |
|
| 113 | } |
||
| 114 | 3 | return $this->_ref; |
|
|
1 ignored issue
–
show
|
|||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | 18 | protected function _qualifierASN1(): Element |
|
| 130 | } |
||
| 131 | } |
||
| 132 |