@@ -16,59 +16,59 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class UniformResourceIdentifier extends GeneralName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * URI. |
|
| 21 | - * |
|
| 22 | - * @var string $_uri |
|
| 23 | - */ |
|
| 24 | - protected $_uri; |
|
| 19 | + /** |
|
| 20 | + * URI. |
|
| 21 | + * |
|
| 22 | + * @var string $_uri |
|
| 23 | + */ |
|
| 24 | + protected $_uri; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param string $uri |
|
| 30 | - */ |
|
| 31 | - public function __construct(string $uri) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_URI; |
|
| 34 | - $this->_uri = $uri; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param string $uri |
|
| 30 | + */ |
|
| 31 | + public function __construct(string $uri) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_URI; |
|
| 34 | + $this->_uri = $uri; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - * @param UnspecifiedType $el |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 43 | - { |
|
| 44 | - return new self($el->asIA5String()->string()); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + * @param UnspecifiedType $el |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 43 | + { |
|
| 44 | + return new self($el->asIA5String()->string()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function string(): string |
|
| 52 | - { |
|
| 53 | - return $this->_uri; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function string(): string |
|
| 52 | + { |
|
| 53 | + return $this->_uri; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get URI. |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function uri(): string |
|
| 62 | - { |
|
| 63 | - return $this->_uri; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get URI. |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function uri(): string |
|
| 62 | + { |
|
| 63 | + return $this->_uri; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - */ |
|
| 70 | - protected function _choiceASN1() |
|
| 71 | - { |
|
| 72 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + */ |
|
| 70 | + protected function _choiceASN1() |
|
| 71 | + { |
|
| 72 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -18,82 +18,82 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class OtherName extends GeneralName |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Type OID. |
|
| 23 | - * |
|
| 24 | - * @var string $_type |
|
| 25 | - */ |
|
| 26 | - protected $_type; |
|
| 21 | + /** |
|
| 22 | + * Type OID. |
|
| 23 | + * |
|
| 24 | + * @var string $_type |
|
| 25 | + */ |
|
| 26 | + protected $_type; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Value. |
|
| 30 | - * |
|
| 31 | - * @var Element $_element |
|
| 32 | - */ |
|
| 33 | - protected $_element; |
|
| 28 | + /** |
|
| 29 | + * Value. |
|
| 30 | + * |
|
| 31 | + * @var Element $_element |
|
| 32 | + */ |
|
| 33 | + protected $_element; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor. |
|
| 37 | - * |
|
| 38 | - * @param string $type_id OID |
|
| 39 | - * @param Element $el |
|
| 40 | - */ |
|
| 41 | - public function __construct($type_id, Element $el) |
|
| 42 | - { |
|
| 43 | - $this->_tag = self::TAG_OTHER_NAME; |
|
| 44 | - $this->_type = $type_id; |
|
| 45 | - $this->_element = $el; |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor. |
|
| 37 | + * |
|
| 38 | + * @param string $type_id OID |
|
| 39 | + * @param Element $el |
|
| 40 | + */ |
|
| 41 | + public function __construct($type_id, Element $el) |
|
| 42 | + { |
|
| 43 | + $this->_tag = self::TAG_OTHER_NAME; |
|
| 44 | + $this->_type = $type_id; |
|
| 45 | + $this->_element = $el; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * |
|
| 50 | - * @param UnspecifiedType $el |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 54 | - { |
|
| 55 | - $seq = $el->asSequence(); |
|
| 56 | - $type_id = $seq->at(0) |
|
| 57 | - ->asObjectIdentifier() |
|
| 58 | - ->oid(); |
|
| 59 | - $value = $seq->getTagged(0) |
|
| 60 | - ->asExplicit() |
|
| 61 | - ->asElement(); |
|
| 62 | - return new self($type_id, $value); |
|
| 63 | - } |
|
| 64 | - public function string() |
|
| 65 | - { |
|
| 66 | - return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
| 67 | - } |
|
| 48 | + /** |
|
| 49 | + * |
|
| 50 | + * @param UnspecifiedType $el |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 54 | + { |
|
| 55 | + $seq = $el->asSequence(); |
|
| 56 | + $type_id = $seq->at(0) |
|
| 57 | + ->asObjectIdentifier() |
|
| 58 | + ->oid(); |
|
| 59 | + $value = $seq->getTagged(0) |
|
| 60 | + ->asExplicit() |
|
| 61 | + ->asElement(); |
|
| 62 | + return new self($type_id, $value); |
|
| 63 | + } |
|
| 64 | + public function string() |
|
| 65 | + { |
|
| 66 | + return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Get type OID. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function type(): string |
|
| 75 | - { |
|
| 76 | - return $this->_type; |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * Get type OID. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function type(): string |
|
| 75 | + { |
|
| 76 | + return $this->_type; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get value element. |
|
| 81 | - * |
|
| 82 | - * @return Element |
|
| 83 | - */ |
|
| 84 | - public function value(): Element |
|
| 85 | - { |
|
| 86 | - return $this->_element; |
|
| 87 | - } |
|
| 79 | + /** |
|
| 80 | + * Get value element. |
|
| 81 | + * |
|
| 82 | + * @return Element |
|
| 83 | + */ |
|
| 84 | + public function value(): Element |
|
| 85 | + { |
|
| 86 | + return $this->_element; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * |
|
| 91 | - * {@inheritdoc} |
|
| 92 | - */ |
|
| 93 | - protected function _choiceASN1() |
|
| 94 | - { |
|
| 95 | - return new ImplicitlyTaggedType($this->_tag, |
|
| 96 | - new Sequence(new ObjectIdentifier($this->_type), |
|
| 97 | - new ExplicitlyTaggedType(0, $this->_element))); |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * |
|
| 91 | + * {@inheritdoc} |
|
| 92 | + */ |
|
| 93 | + protected function _choiceASN1() |
|
| 94 | + { |
|
| 95 | + return new ImplicitlyTaggedType($this->_tag, |
|
| 96 | + new Sequence(new ObjectIdentifier($this->_type), |
|
| 97 | + new ExplicitlyTaggedType(0, $this->_element))); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -15,60 +15,60 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class RegisteredID extends GeneralName |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Object identifier. |
|
| 20 | - * |
|
| 21 | - * @var string $_oid |
|
| 22 | - */ |
|
| 23 | - protected $_oid; |
|
| 18 | + /** |
|
| 19 | + * Object identifier. |
|
| 20 | + * |
|
| 21 | + * @var string $_oid |
|
| 22 | + */ |
|
| 23 | + protected $_oid; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Constructor. |
|
| 27 | - * |
|
| 28 | - * @param string $oid OID in dotted format |
|
| 29 | - */ |
|
| 30 | - public function __construct(string $oid) |
|
| 31 | - { |
|
| 32 | - $this->_tag = self::TAG_REGISTERED_ID; |
|
| 33 | - $this->_oid = $oid; |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * Constructor. |
|
| 27 | + * |
|
| 28 | + * @param string $oid OID in dotted format |
|
| 29 | + */ |
|
| 30 | + public function __construct(string $oid) |
|
| 31 | + { |
|
| 32 | + $this->_tag = self::TAG_REGISTERED_ID; |
|
| 33 | + $this->_oid = $oid; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - * @param UnspecifiedType $el |
|
| 39 | - * @return self |
|
| 40 | - */ |
|
| 41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | - { |
|
| 43 | - return new self($el->asObjectIdentifier()->oid()); |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + * @param UnspecifiedType $el |
|
| 39 | + * @return self |
|
| 40 | + */ |
|
| 41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | + { |
|
| 43 | + return new self($el->asObjectIdentifier()->oid()); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - public function string(): string |
|
| 51 | - { |
|
| 52 | - return $this->_oid; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + public function string(): string |
|
| 51 | + { |
|
| 52 | + return $this->_oid; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get object identifier in dotted format. |
|
| 57 | - * |
|
| 58 | - * @return string OID |
|
| 59 | - */ |
|
| 60 | - public function oid(): string |
|
| 61 | - { |
|
| 62 | - return $this->_oid; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Get object identifier in dotted format. |
|
| 57 | + * |
|
| 58 | + * @return string OID |
|
| 59 | + */ |
|
| 60 | + public function oid(): string |
|
| 61 | + { |
|
| 62 | + return $this->_oid; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * |
|
| 67 | - * {@inheritdoc} |
|
| 68 | - */ |
|
| 69 | - protected function _choiceASN1() |
|
| 70 | - { |
|
| 71 | - return new ImplicitlyTaggedType($this->_tag, |
|
| 72 | - new ObjectIdentifier($this->_oid)); |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * |
|
| 67 | + * {@inheritdoc} |
|
| 68 | + */ |
|
| 69 | + protected function _choiceASN1() |
|
| 70 | + { |
|
| 71 | + return new ImplicitlyTaggedType($this->_tag, |
|
| 72 | + new ObjectIdentifier($this->_oid)); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -17,183 +17,183 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class GeneralNames implements \Countable, \IteratorAggregate |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * GeneralName objects. |
|
| 22 | - * |
|
| 23 | - * @var GeneralName[] $_names |
|
| 24 | - */ |
|
| 25 | - protected $_names; |
|
| 20 | + /** |
|
| 21 | + * GeneralName objects. |
|
| 22 | + * |
|
| 23 | + * @var GeneralName[] $_names |
|
| 24 | + */ |
|
| 25 | + protected $_names; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param GeneralName ...$names One or more GeneralName objects |
|
| 31 | - */ |
|
| 32 | - public function __construct(GeneralName ...$names) |
|
| 33 | - { |
|
| 34 | - $this->_names = $names; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param GeneralName ...$names One or more GeneralName objects |
|
| 31 | + */ |
|
| 32 | + public function __construct(GeneralName ...$names) |
|
| 33 | + { |
|
| 34 | + $this->_names = $names; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Initialize from ASN.1. |
|
| 39 | - * |
|
| 40 | - * @param Sequence $seq |
|
| 41 | - * @throws \UnexpectedValueException |
|
| 42 | - * @return self |
|
| 43 | - */ |
|
| 44 | - public static function fromASN1(Sequence $seq) |
|
| 45 | - { |
|
| 46 | - if (!count($seq)) { |
|
| 47 | - throw new \UnexpectedValueException( |
|
| 48 | - "GeneralNames must have at least one GeneralName."); |
|
| 49 | - } |
|
| 50 | - $names = array_map( |
|
| 51 | - function (UnspecifiedType $el) { |
|
| 52 | - return GeneralName::fromASN1($el->asTagged()); |
|
| 53 | - }, $seq->elements()); |
|
| 54 | - return new self(...$names); |
|
| 55 | - } |
|
| 37 | + /** |
|
| 38 | + * Initialize from ASN.1. |
|
| 39 | + * |
|
| 40 | + * @param Sequence $seq |
|
| 41 | + * @throws \UnexpectedValueException |
|
| 42 | + * @return self |
|
| 43 | + */ |
|
| 44 | + public static function fromASN1(Sequence $seq) |
|
| 45 | + { |
|
| 46 | + if (!count($seq)) { |
|
| 47 | + throw new \UnexpectedValueException( |
|
| 48 | + "GeneralNames must have at least one GeneralName."); |
|
| 49 | + } |
|
| 50 | + $names = array_map( |
|
| 51 | + function (UnspecifiedType $el) { |
|
| 52 | + return GeneralName::fromASN1($el->asTagged()); |
|
| 53 | + }, $seq->elements()); |
|
| 54 | + return new self(...$names); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Find first GeneralName by given tag. |
|
| 59 | - * |
|
| 60 | - * @param int $tag |
|
| 61 | - * @return GeneralName|null |
|
| 62 | - */ |
|
| 63 | - protected function _findFirst($tag) |
|
| 64 | - { |
|
| 65 | - foreach ($this->_names as $name) { |
|
| 66 | - if ($name->tag() == $tag) { |
|
| 67 | - return $name; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return null; |
|
| 71 | - } |
|
| 57 | + /** |
|
| 58 | + * Find first GeneralName by given tag. |
|
| 59 | + * |
|
| 60 | + * @param int $tag |
|
| 61 | + * @return GeneralName|null |
|
| 62 | + */ |
|
| 63 | + protected function _findFirst($tag) |
|
| 64 | + { |
|
| 65 | + foreach ($this->_names as $name) { |
|
| 66 | + if ($name->tag() == $tag) { |
|
| 67 | + return $name; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return null; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Check whether GeneralNames contains a GeneralName of given type. |
|
| 75 | - * |
|
| 76 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 77 | - * @return bool |
|
| 78 | - */ |
|
| 79 | - public function has($tag): bool |
|
| 80 | - { |
|
| 81 | - return null !== $this->_findFirst($tag); |
|
| 82 | - } |
|
| 73 | + /** |
|
| 74 | + * Check whether GeneralNames contains a GeneralName of given type. |
|
| 75 | + * |
|
| 76 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 77 | + * @return bool |
|
| 78 | + */ |
|
| 79 | + public function has($tag): bool |
|
| 80 | + { |
|
| 81 | + return null !== $this->_findFirst($tag); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get first GeneralName of given type. |
|
| 86 | - * |
|
| 87 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 88 | - * @throws \OutOfBoundsException |
|
| 89 | - * @return GeneralName |
|
| 90 | - */ |
|
| 91 | - public function firstOf($tag): GeneralName |
|
| 92 | - { |
|
| 93 | - $name = $this->_findFirst($tag); |
|
| 94 | - if (!$name) { |
|
| 95 | - throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
| 96 | - } |
|
| 97 | - return $name; |
|
| 98 | - } |
|
| 84 | + /** |
|
| 85 | + * Get first GeneralName of given type. |
|
| 86 | + * |
|
| 87 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 88 | + * @throws \OutOfBoundsException |
|
| 89 | + * @return GeneralName |
|
| 90 | + */ |
|
| 91 | + public function firstOf($tag): GeneralName |
|
| 92 | + { |
|
| 93 | + $name = $this->_findFirst($tag); |
|
| 94 | + if (!$name) { |
|
| 95 | + throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
| 96 | + } |
|
| 97 | + return $name; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Get all GeneralName objects of given type. |
|
| 102 | - * |
|
| 103 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 104 | - * @return GeneralName[] |
|
| 105 | - */ |
|
| 106 | - public function allOf($tag): array |
|
| 107 | - { |
|
| 108 | - $names = array_filter($this->_names, |
|
| 109 | - function (GeneralName $name) use ($tag) { |
|
| 110 | - return $name->tag() == $tag; |
|
| 111 | - }); |
|
| 112 | - return array_values($names); |
|
| 113 | - } |
|
| 100 | + /** |
|
| 101 | + * Get all GeneralName objects of given type. |
|
| 102 | + * |
|
| 103 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
| 104 | + * @return GeneralName[] |
|
| 105 | + */ |
|
| 106 | + public function allOf($tag): array |
|
| 107 | + { |
|
| 108 | + $names = array_filter($this->_names, |
|
| 109 | + function (GeneralName $name) use ($tag) { |
|
| 110 | + return $name->tag() == $tag; |
|
| 111 | + }); |
|
| 112 | + return array_values($names); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Get value of the first 'dNSName' type. |
|
| 117 | - * |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function firstDNS(): string |
|
| 121 | - { |
|
| 122 | - $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
| 123 | - if (!$gn instanceof DNSName) { |
|
| 124 | - throw new \RuntimeException( |
|
| 125 | - DNSName::class . " expected, got " . get_class($gn)); |
|
| 126 | - } |
|
| 127 | - return $gn->name(); |
|
| 128 | - } |
|
| 115 | + /** |
|
| 116 | + * Get value of the first 'dNSName' type. |
|
| 117 | + * |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function firstDNS(): string |
|
| 121 | + { |
|
| 122 | + $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
| 123 | + if (!$gn instanceof DNSName) { |
|
| 124 | + throw new \RuntimeException( |
|
| 125 | + DNSName::class . " expected, got " . get_class($gn)); |
|
| 126 | + } |
|
| 127 | + return $gn->name(); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Get value of the first 'directoryName' type. |
|
| 132 | - * |
|
| 133 | - * @return \X501\ASN1\Name |
|
| 134 | - */ |
|
| 135 | - public function firstDN(): \X501\ASN1\Name |
|
| 136 | - { |
|
| 137 | - $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
| 138 | - if (!$gn instanceof DirectoryName) { |
|
| 139 | - throw new \RuntimeException( |
|
| 140 | - DirectoryName::class . " expected, got " . get_class($gn)); |
|
| 141 | - } |
|
| 142 | - return $gn->dn(); |
|
| 143 | - } |
|
| 130 | + /** |
|
| 131 | + * Get value of the first 'directoryName' type. |
|
| 132 | + * |
|
| 133 | + * @return \X501\ASN1\Name |
|
| 134 | + */ |
|
| 135 | + public function firstDN(): \X501\ASN1\Name |
|
| 136 | + { |
|
| 137 | + $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
| 138 | + if (!$gn instanceof DirectoryName) { |
|
| 139 | + throw new \RuntimeException( |
|
| 140 | + DirectoryName::class . " expected, got " . get_class($gn)); |
|
| 141 | + } |
|
| 142 | + return $gn->dn(); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Get value of the first 'uniformResourceIdentifier' type. |
|
| 147 | - * |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - public function firstURI(): string |
|
| 151 | - { |
|
| 152 | - $gn = $this->firstOf(GeneralName::TAG_URI); |
|
| 153 | - if (!$gn instanceof UniformResourceIdentifier) { |
|
| 154 | - throw new \RuntimeException( |
|
| 155 | - UniformResourceIdentifier::class . " expected, got " . |
|
| 156 | - get_class($gn)); |
|
| 157 | - } |
|
| 158 | - return $gn->uri(); |
|
| 159 | - } |
|
| 145 | + /** |
|
| 146 | + * Get value of the first 'uniformResourceIdentifier' type. |
|
| 147 | + * |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + public function firstURI(): string |
|
| 151 | + { |
|
| 152 | + $gn = $this->firstOf(GeneralName::TAG_URI); |
|
| 153 | + if (!$gn instanceof UniformResourceIdentifier) { |
|
| 154 | + throw new \RuntimeException( |
|
| 155 | + UniformResourceIdentifier::class . " expected, got " . |
|
| 156 | + get_class($gn)); |
|
| 157 | + } |
|
| 158 | + return $gn->uri(); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Generate ASN.1 structure. |
|
| 163 | - * |
|
| 164 | - * @return Sequence |
|
| 165 | - */ |
|
| 166 | - public function toASN1(): Sequence |
|
| 167 | - { |
|
| 168 | - if (!count($this->_names)) { |
|
| 169 | - throw new \LogicException( |
|
| 170 | - "GeneralNames must have at least one GeneralName."); |
|
| 171 | - } |
|
| 172 | - $elements = array_map( |
|
| 173 | - function (GeneralName $name) { |
|
| 174 | - return $name->toASN1(); |
|
| 175 | - }, $this->_names); |
|
| 176 | - return new Sequence(...$elements); |
|
| 177 | - } |
|
| 161 | + /** |
|
| 162 | + * Generate ASN.1 structure. |
|
| 163 | + * |
|
| 164 | + * @return Sequence |
|
| 165 | + */ |
|
| 166 | + public function toASN1(): Sequence |
|
| 167 | + { |
|
| 168 | + if (!count($this->_names)) { |
|
| 169 | + throw new \LogicException( |
|
| 170 | + "GeneralNames must have at least one GeneralName."); |
|
| 171 | + } |
|
| 172 | + $elements = array_map( |
|
| 173 | + function (GeneralName $name) { |
|
| 174 | + return $name->toASN1(); |
|
| 175 | + }, $this->_names); |
|
| 176 | + return new Sequence(...$elements); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * |
|
| 181 | - * @see \Countable::count() |
|
| 182 | - * @return int |
|
| 183 | - */ |
|
| 184 | - public function count(): int |
|
| 185 | - { |
|
| 186 | - return count($this->_names); |
|
| 187 | - } |
|
| 179 | + /** |
|
| 180 | + * |
|
| 181 | + * @see \Countable::count() |
|
| 182 | + * @return int |
|
| 183 | + */ |
|
| 184 | + public function count(): int |
|
| 185 | + { |
|
| 186 | + return count($this->_names); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Get iterator for GeneralName objects. |
|
| 191 | - * |
|
| 192 | - * @see \IteratorAggregate::getIterator() |
|
| 193 | - * @return \ArrayIterator |
|
| 194 | - */ |
|
| 195 | - public function getIterator(): \ArrayIterator |
|
| 196 | - { |
|
| 197 | - return new \ArrayIterator($this->_names); |
|
| 198 | - } |
|
| 189 | + /** |
|
| 190 | + * Get iterator for GeneralName objects. |
|
| 191 | + * |
|
| 192 | + * @see \IteratorAggregate::getIterator() |
|
| 193 | + * @return \ArrayIterator |
|
| 194 | + */ |
|
| 195 | + public function getIterator(): \ArrayIterator |
|
| 196 | + { |
|
| 197 | + return new \ArrayIterator($this->_names); |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | "GeneralNames must have at least one GeneralName."); |
| 49 | 49 | } |
| 50 | 50 | $names = array_map( |
| 51 | - function (UnspecifiedType $el) { |
|
| 51 | + function(UnspecifiedType $el) { |
|
| 52 | 52 | return GeneralName::fromASN1($el->asTagged()); |
| 53 | 53 | }, $seq->elements()); |
| 54 | 54 | return new self(...$names); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | public function allOf($tag): array |
| 107 | 107 | { |
| 108 | 108 | $names = array_filter($this->_names, |
| 109 | - function (GeneralName $name) use ($tag) { |
|
| 109 | + function(GeneralName $name) use ($tag) { |
|
| 110 | 110 | return $name->tag() == $tag; |
| 111 | 111 | }); |
| 112 | 112 | return array_values($names); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | "GeneralNames must have at least one GeneralName."); |
| 171 | 171 | } |
| 172 | 172 | $elements = array_map( |
| 173 | - function (GeneralName $name) { |
|
| 173 | + function(GeneralName $name) { |
|
| 174 | 174 | return $name->toASN1(); |
| 175 | 175 | }, $this->_names); |
| 176 | 176 | return new Sequence(...$elements); |
@@ -15,59 +15,59 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class RFC822Name extends GeneralName |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Email. |
|
| 20 | - * |
|
| 21 | - * @var string $_email |
|
| 22 | - */ |
|
| 23 | - protected $_email; |
|
| 18 | + /** |
|
| 19 | + * Email. |
|
| 20 | + * |
|
| 21 | + * @var string $_email |
|
| 22 | + */ |
|
| 23 | + protected $_email; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Constructor. |
|
| 27 | - * |
|
| 28 | - * @param string $email |
|
| 29 | - */ |
|
| 30 | - public function __construct(string $email) |
|
| 31 | - { |
|
| 32 | - $this->_tag = self::TAG_RFC822_NAME; |
|
| 33 | - $this->_email = $email; |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * Constructor. |
|
| 27 | + * |
|
| 28 | + * @param string $email |
|
| 29 | + */ |
|
| 30 | + public function __construct(string $email) |
|
| 31 | + { |
|
| 32 | + $this->_tag = self::TAG_RFC822_NAME; |
|
| 33 | + $this->_email = $email; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - * @param UnspecifiedType $el |
|
| 39 | - * @return self |
|
| 40 | - */ |
|
| 41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | - { |
|
| 43 | - return new self($el->asIA5String()->string()); |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + * @param UnspecifiedType $el |
|
| 39 | + * @return self |
|
| 40 | + */ |
|
| 41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | + { |
|
| 43 | + return new self($el->asIA5String()->string()); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - public function string(): string |
|
| 51 | - { |
|
| 52 | - return $this->_email; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + public function string(): string |
|
| 51 | + { |
|
| 52 | + return $this->_email; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get email. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function email(): string |
|
| 61 | - { |
|
| 62 | - return $this->_email; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Get email. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function email(): string |
|
| 61 | + { |
|
| 62 | + return $this->_email; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * |
|
| 67 | - * {@inheritdoc} |
|
| 68 | - */ |
|
| 69 | - protected function _choiceASN1() |
|
| 70 | - { |
|
| 71 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
| 72 | - } |
|
| 65 | + /** |
|
| 66 | + * |
|
| 67 | + * {@inheritdoc} |
|
| 68 | + */ |
|
| 69 | + protected function _choiceASN1() |
|
| 70 | + { |
|
| 71 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -15,72 +15,72 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class DirectoryName extends GeneralName |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Directory name. |
|
| 20 | - * |
|
| 21 | - * @var Name $_dn |
|
| 22 | - */ |
|
| 23 | - protected $_dn; |
|
| 18 | + /** |
|
| 19 | + * Directory name. |
|
| 20 | + * |
|
| 21 | + * @var Name $_dn |
|
| 22 | + */ |
|
| 23 | + protected $_dn; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Constructor. |
|
| 27 | - * |
|
| 28 | - * @param Name $dn |
|
| 29 | - */ |
|
| 30 | - public function __construct(Name $dn) |
|
| 31 | - { |
|
| 32 | - $this->_tag = self::TAG_DIRECTORY_NAME; |
|
| 33 | - $this->_dn = $dn; |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * Constructor. |
|
| 27 | + * |
|
| 28 | + * @param Name $dn |
|
| 29 | + */ |
|
| 30 | + public function __construct(Name $dn) |
|
| 31 | + { |
|
| 32 | + $this->_tag = self::TAG_DIRECTORY_NAME; |
|
| 33 | + $this->_dn = $dn; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - * @param UnspecifiedType $el |
|
| 39 | - * @return self |
|
| 40 | - */ |
|
| 41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | - { |
|
| 43 | - return new self(Name::fromASN1($el->asSequence())); |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + * @param UnspecifiedType $el |
|
| 39 | + * @return self |
|
| 40 | + */ |
|
| 41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 42 | + { |
|
| 43 | + return new self(Name::fromASN1($el->asSequence())); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from distinguished name string. |
|
| 48 | - * |
|
| 49 | - * @param string $str |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - public static function fromDNString($str) |
|
| 53 | - { |
|
| 54 | - return new self(Name::fromString($str)); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from distinguished name string. |
|
| 48 | + * |
|
| 49 | + * @param string $str |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + public static function fromDNString($str) |
|
| 53 | + { |
|
| 54 | + return new self(Name::fromString($str)); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * |
|
| 59 | - * {@inheritdoc} |
|
| 60 | - */ |
|
| 61 | - public function string(): string |
|
| 62 | - { |
|
| 63 | - return $this->_dn->toString(); |
|
| 64 | - } |
|
| 57 | + /** |
|
| 58 | + * |
|
| 59 | + * {@inheritdoc} |
|
| 60 | + */ |
|
| 61 | + public function string(): string |
|
| 62 | + { |
|
| 63 | + return $this->_dn->toString(); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Get directory name. |
|
| 68 | - * |
|
| 69 | - * @return Name |
|
| 70 | - */ |
|
| 71 | - public function dn(): Name |
|
| 72 | - { |
|
| 73 | - return $this->_dn; |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Get directory name. |
|
| 68 | + * |
|
| 69 | + * @return Name |
|
| 70 | + */ |
|
| 71 | + public function dn(): Name |
|
| 72 | + { |
|
| 73 | + return $this->_dn; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - */ |
|
| 80 | - protected function _choiceASN1() |
|
| 81 | - { |
|
| 82 | - // Name type is itself a CHOICE, so explicit tagging must be |
|
| 83 | - // employed to avoid ambiguities |
|
| 84 | - return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
| 85 | - } |
|
| 76 | + /** |
|
| 77 | + * |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + */ |
|
| 80 | + protected function _choiceASN1() |
|
| 81 | + { |
|
| 82 | + // Name type is itself a CHOICE, so explicit tagging must be |
|
| 83 | + // employed to avoid ambiguities |
|
| 84 | + return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -15,47 +15,47 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EDIPartyName extends GeneralName |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * |
|
| 20 | - * @var \ASN1\Element |
|
| 21 | - */ |
|
| 22 | - protected $_element; |
|
| 18 | + /** |
|
| 19 | + * |
|
| 20 | + * @var \ASN1\Element |
|
| 21 | + */ |
|
| 22 | + protected $_element; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Constructor. |
|
| 26 | - */ |
|
| 27 | - protected function __construct() |
|
| 28 | - { |
|
| 29 | - $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
| 30 | - } |
|
| 24 | + /** |
|
| 25 | + * Constructor. |
|
| 26 | + */ |
|
| 27 | + protected function __construct() |
|
| 28 | + { |
|
| 29 | + $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - * @param UnspecifiedType $el |
|
| 35 | - * @return self |
|
| 36 | - */ |
|
| 37 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 38 | - { |
|
| 39 | - $obj = new self(); |
|
| 40 | - $obj->_element = $el->asSequence(); |
|
| 41 | - return $obj; |
|
| 42 | - } |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + * @param UnspecifiedType $el |
|
| 35 | + * @return self |
|
| 36 | + */ |
|
| 37 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 38 | + { |
|
| 39 | + $obj = new self(); |
|
| 40 | + $obj->_element = $el->asSequence(); |
|
| 41 | + return $obj; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * {@inheritdoc} |
|
| 47 | - */ |
|
| 48 | - public function string(): string |
|
| 49 | - { |
|
| 50 | - return bin2hex($this->_element->toDER()); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * {@inheritdoc} |
|
| 47 | + */ |
|
| 48 | + public function string(): string |
|
| 49 | + { |
|
| 50 | + return bin2hex($this->_element->toDER()); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * |
|
| 55 | - * {@inheritdoc} |
|
| 56 | - */ |
|
| 57 | - protected function _choiceASN1() |
|
| 58 | - { |
|
| 59 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 60 | - } |
|
| 53 | + /** |
|
| 54 | + * |
|
| 55 | + * {@inheritdoc} |
|
| 56 | + */ |
|
| 57 | + protected function _choiceASN1() |
|
| 58 | + { |
|
| 59 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -17,47 +17,47 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class X400Address extends GeneralName |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * @var \ASN1\Element |
|
| 23 | - */ |
|
| 24 | - protected $_element; |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * @var \ASN1\Element |
|
| 23 | + */ |
|
| 24 | + protected $_element; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - */ |
|
| 29 | - protected function __construct() |
|
| 30 | - { |
|
| 31 | - $this->_tag = self::TAG_X400_ADDRESS; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + */ |
|
| 29 | + protected function __construct() |
|
| 30 | + { |
|
| 31 | + $this->_tag = self::TAG_X400_ADDRESS; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * @param UnspecifiedType $el |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 40 | - { |
|
| 41 | - $obj = new self(); |
|
| 42 | - $obj->_element = $el->asSequence(); |
|
| 43 | - return $obj; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * @param UnspecifiedType $el |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 40 | + { |
|
| 41 | + $obj = new self(); |
|
| 42 | + $obj->_element = $el->asSequence(); |
|
| 43 | + return $obj; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - public function string(): string |
|
| 51 | - { |
|
| 52 | - return bin2hex($this->_element->toDER()); |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + public function string(): string |
|
| 51 | + { |
|
| 52 | + return bin2hex($this->_element->toDER()); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * |
|
| 57 | - * {@inheritdoc} |
|
| 58 | - */ |
|
| 59 | - protected function _choiceASN1() |
|
| 60 | - { |
|
| 61 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * |
|
| 57 | + * {@inheritdoc} |
|
| 58 | + */ |
|
| 59 | + protected function _choiceASN1() |
|
| 60 | + { |
|
| 61 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\GeneralName; |
| 6 | 6 | |
@@ -7,67 +7,67 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | trait DateTimeHelper |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Create DateTime object from time string and timezone. |
|
| 12 | - * |
|
| 13 | - * @param string|null $time Time string, default to 'now' |
|
| 14 | - * @param string|null $tz Timezone, default if omitted |
|
| 15 | - * @throws \RuntimeException |
|
| 16 | - * @return \DateTimeImmutable |
|
| 17 | - */ |
|
| 18 | - private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable |
|
| 19 | - { |
|
| 20 | - try { |
|
| 21 | - if (!isset($tz)) { |
|
| 22 | - $tz = date_default_timezone_get(); |
|
| 23 | - } |
|
| 10 | + /** |
|
| 11 | + * Create DateTime object from time string and timezone. |
|
| 12 | + * |
|
| 13 | + * @param string|null $time Time string, default to 'now' |
|
| 14 | + * @param string|null $tz Timezone, default if omitted |
|
| 15 | + * @throws \RuntimeException |
|
| 16 | + * @return \DateTimeImmutable |
|
| 17 | + */ |
|
| 18 | + private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable |
|
| 19 | + { |
|
| 20 | + try { |
|
| 21 | + if (!isset($tz)) { |
|
| 22 | + $tz = date_default_timezone_get(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
| 26 | - return self::_roundDownFractionalSeconds($dt); |
|
| 27 | - } catch (\Exception $e) { |
|
| 28 | - throw new \RuntimeException( |
|
| 29 | - "Failed to create DateTime: " . |
|
| 30 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 31 | - } |
|
| 32 | - } |
|
| 25 | + $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
| 26 | + return self::_roundDownFractionalSeconds($dt); |
|
| 27 | + } catch (\Exception $e) { |
|
| 28 | + throw new \RuntimeException( |
|
| 29 | + "Failed to create DateTime: " . |
|
| 30 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Rounds a \DateTimeImmutable value such that fractional |
|
| 36 | - * seconds are removed. |
|
| 37 | - * |
|
| 38 | - * @param \DateTimeImmutable $dt |
|
| 39 | - * @return \DateTimeImmutable |
|
| 40 | - */ |
|
| 41 | - private static function _roundDownFractionalSeconds(\DateTimeImmutable $dt): \DateTimeImmutable |
|
| 42 | - { |
|
| 43 | - return \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
| 44 | - $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * Rounds a \DateTimeImmutable value such that fractional |
|
| 36 | + * seconds are removed. |
|
| 37 | + * |
|
| 38 | + * @param \DateTimeImmutable $dt |
|
| 39 | + * @return \DateTimeImmutable |
|
| 40 | + */ |
|
| 41 | + private static function _roundDownFractionalSeconds(\DateTimeImmutable $dt): \DateTimeImmutable |
|
| 42 | + { |
|
| 43 | + return \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
| 44 | + $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Create DateTimeZone object from string. |
|
| 49 | - * |
|
| 50 | - * @param string $tz |
|
| 51 | - * @throws \UnexpectedValueException |
|
| 52 | - * @return \DateTimeZone |
|
| 53 | - */ |
|
| 54 | - private static function _createTimeZone($tz) |
|
| 55 | - { |
|
| 56 | - try { |
|
| 57 | - return new \DateTimeZone($tz); |
|
| 58 | - } catch (\Exception $e) { |
|
| 59 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 60 | - } |
|
| 61 | - } |
|
| 47 | + /** |
|
| 48 | + * Create DateTimeZone object from string. |
|
| 49 | + * |
|
| 50 | + * @param string $tz |
|
| 51 | + * @throws \UnexpectedValueException |
|
| 52 | + * @return \DateTimeZone |
|
| 53 | + */ |
|
| 54 | + private static function _createTimeZone($tz) |
|
| 55 | + { |
|
| 56 | + try { |
|
| 57 | + return new \DateTimeZone($tz); |
|
| 58 | + } catch (\Exception $e) { |
|
| 59 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Get last error caused by DateTimeImmutable. |
|
| 65 | - * |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - private static function _getLastDateTimeImmutableErrorsStr() |
|
| 69 | - { |
|
| 70 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 71 | - return implode(", ", $errors); |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Get last error caused by DateTimeImmutable. |
|
| 65 | + * |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + private static function _getLastDateTimeImmutableErrorsStr() |
|
| 69 | + { |
|
| 70 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 71 | + return implode(", ", $errors); |
|
| 72 | + } |
|
| 73 | 73 | } |