@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace ASN1\Type; |
| 6 | 6 | |
@@ -10,88 +10,88 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | abstract class TimeType extends Element |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * UTC timezone. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - const TZ_UTC = "UTC"; |
|
| 13 | + /** |
|
| 14 | + * UTC timezone. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + const TZ_UTC = "UTC"; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Date and time. |
|
| 22 | - * |
|
| 23 | - * @var \DateTimeImmutable $_dateTime |
|
| 24 | - */ |
|
| 25 | - protected $_dateTime; |
|
| 20 | + /** |
|
| 21 | + * Date and time. |
|
| 22 | + * |
|
| 23 | + * @var \DateTimeImmutable $_dateTime |
|
| 24 | + */ |
|
| 25 | + protected $_dateTime; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param \DateTimeImmutable $dt |
|
| 31 | - */ |
|
| 32 | - public function __construct(\DateTimeImmutable $dt) |
|
| 33 | - { |
|
| 34 | - $this->_dateTime = $dt; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param \DateTimeImmutable $dt |
|
| 31 | + */ |
|
| 32 | + public function __construct(\DateTimeImmutable $dt) |
|
| 33 | + { |
|
| 34 | + $this->_dateTime = $dt; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Initialize from datetime string. |
|
| 39 | - * |
|
| 40 | - * @link http://php.net/manual/en/datetime.formats.php |
|
| 41 | - * @param string $time Time string |
|
| 42 | - * @param string|null $tz Timezone, if null use default. |
|
| 43 | - * @throws \RuntimeException |
|
| 44 | - * @return self |
|
| 45 | - */ |
|
| 46 | - public static function fromString(string $time, string $tz = null): self |
|
| 47 | - { |
|
| 48 | - try { |
|
| 49 | - if (!isset($tz)) { |
|
| 50 | - $tz = date_default_timezone_get(); |
|
| 51 | - } |
|
| 52 | - return new static( |
|
| 53 | - new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
| 54 | - } catch (\Exception $e) { |
|
| 55 | - throw new \RuntimeException( |
|
| 56 | - "Failed to create DateTime: " . |
|
| 57 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 58 | - } |
|
| 59 | - } |
|
| 37 | + /** |
|
| 38 | + * Initialize from datetime string. |
|
| 39 | + * |
|
| 40 | + * @link http://php.net/manual/en/datetime.formats.php |
|
| 41 | + * @param string $time Time string |
|
| 42 | + * @param string|null $tz Timezone, if null use default. |
|
| 43 | + * @throws \RuntimeException |
|
| 44 | + * @return self |
|
| 45 | + */ |
|
| 46 | + public static function fromString(string $time, string $tz = null): self |
|
| 47 | + { |
|
| 48 | + try { |
|
| 49 | + if (!isset($tz)) { |
|
| 50 | + $tz = date_default_timezone_get(); |
|
| 51 | + } |
|
| 52 | + return new static( |
|
| 53 | + new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
| 54 | + } catch (\Exception $e) { |
|
| 55 | + throw new \RuntimeException( |
|
| 56 | + "Failed to create DateTime: " . |
|
| 57 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the date and time. |
|
| 63 | - * |
|
| 64 | - * @return \DateTimeImmutable |
|
| 65 | - */ |
|
| 66 | - public function dateTime(): \DateTimeImmutable |
|
| 67 | - { |
|
| 68 | - return $this->_dateTime; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the date and time. |
|
| 63 | + * |
|
| 64 | + * @return \DateTimeImmutable |
|
| 65 | + */ |
|
| 66 | + public function dateTime(): \DateTimeImmutable |
|
| 67 | + { |
|
| 68 | + return $this->_dateTime; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Create DateTimeZone object from string. |
|
| 73 | - * |
|
| 74 | - * @param string $tz |
|
| 75 | - * @throws \UnexpectedValueException If timezone is invalid |
|
| 76 | - * @return \DateTimeZone |
|
| 77 | - */ |
|
| 78 | - protected static function _createTimeZone(string $tz): \DateTimeZone |
|
| 79 | - { |
|
| 80 | - try { |
|
| 81 | - return new \DateTimeZone($tz); |
|
| 82 | - } catch (\Exception $e) { |
|
| 83 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 84 | - } |
|
| 85 | - } |
|
| 71 | + /** |
|
| 72 | + * Create DateTimeZone object from string. |
|
| 73 | + * |
|
| 74 | + * @param string $tz |
|
| 75 | + * @throws \UnexpectedValueException If timezone is invalid |
|
| 76 | + * @return \DateTimeZone |
|
| 77 | + */ |
|
| 78 | + protected static function _createTimeZone(string $tz): \DateTimeZone |
|
| 79 | + { |
|
| 80 | + try { |
|
| 81 | + return new \DateTimeZone($tz); |
|
| 82 | + } catch (\Exception $e) { |
|
| 83 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Get last error caused by DateTimeImmutable. |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 93 | - { |
|
| 94 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 95 | - return implode(", ", $errors); |
|
| 96 | - } |
|
| 87 | + /** |
|
| 88 | + * Get last error caused by DateTimeImmutable. |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 93 | + { |
|
| 94 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 95 | + return implode(", ", $errors); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -16,41 +16,41 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class EOC extends Element |
| 18 | 18 | { |
| 19 | - use UniversalClass; |
|
| 20 | - use PrimitiveType; |
|
| 19 | + use UniversalClass; |
|
| 20 | + use PrimitiveType; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Constructor. |
|
| 24 | - */ |
|
| 25 | - public function __construct() |
|
| 26 | - { |
|
| 27 | - $this->_typeTag = self::TYPE_EOC; |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * Constructor. |
|
| 24 | + */ |
|
| 25 | + public function __construct() |
|
| 26 | + { |
|
| 27 | + $this->_typeTag = self::TYPE_EOC; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - * {@inheritdoc} |
|
| 33 | - */ |
|
| 34 | - protected function _encodedContentDER(): string |
|
| 35 | - { |
|
| 36 | - return ''; |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + * {@inheritdoc} |
|
| 33 | + */ |
|
| 34 | + protected function _encodedContentDER(): string |
|
| 35 | + { |
|
| 36 | + return ''; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * |
|
| 41 | - * {@inheritdoc} |
|
| 42 | - * @return self |
|
| 43 | - */ |
|
| 44 | - protected static function _decodeFromDER(Identifier $identifier, |
|
| 45 | - string $data, int &$offset): ElementBase |
|
| 46 | - { |
|
| 47 | - $idx = $offset; |
|
| 48 | - if (!$identifier->isPrimitive()) { |
|
| 49 | - throw new DecodeException("EOC value must be primitive."); |
|
| 50 | - } |
|
| 51 | - // EOC type has always zero length |
|
| 52 | - Length::expectFromDER($data, $idx, 0); |
|
| 53 | - $offset = $idx; |
|
| 54 | - return new self(); |
|
| 55 | - } |
|
| 39 | + /** |
|
| 40 | + * |
|
| 41 | + * {@inheritdoc} |
|
| 42 | + * @return self |
|
| 43 | + */ |
|
| 44 | + protected static function _decodeFromDER(Identifier $identifier, |
|
| 45 | + string $data, int &$offset): ElementBase |
|
| 46 | + { |
|
| 47 | + $idx = $offset; |
|
| 48 | + if (!$identifier->isPrimitive()) { |
|
| 49 | + throw new DecodeException("EOC value must be primitive."); |
|
| 50 | + } |
|
| 51 | + // EOC type has always zero length |
|
| 52 | + Length::expectFromDER($data, $idx, 0); |
|
| 53 | + $offset = $idx; |
|
| 54 | + return new self(); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace ASN1\Type\Primitive; |
| 6 | 6 | |