PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / FG / ASN1 / AbstractTime.php

AbstractTime.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/FG/ASN1/AbstractTime.php

79 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the PHPASN1 library.
4 *
5 * Copyright © Friedrich Große <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace WP_DEFENDER_VENDOR\FG\ASN1;
12
13 use DateInterval;
14 use DateTime;
15 use DateTimeZone;
16 use Exception;
17
18 abstract class AbstractTime extends ASNObject
19 {
20 /** @var DateTime */
21 protected $value;
22
23 public function __construct($dateTime = null, $dateTimeZone = 'UTC')
24 {
25 if ($dateTime == null || is_string($dateTime)) {
26 $timeZone = new DateTimeZone($dateTimeZone);
27 $dateTimeObject = new DateTime($dateTime, $timeZone);
28 if ($dateTimeObject == false) {
29 $errorMessage = $this->getLastDateTimeErrors();
30 $className = Identifier::getName($this->getType());
31 throw new Exception(sprintf("Could not create %s from date time string '%s': %s", $className, $dateTime, $errorMessage));
32 }
33 $dateTime = $dateTimeObject;
34 } elseif (!$dateTime instanceof DateTime) {
35 throw new Exception('Invalid first argument for some instance of AbstractTime constructor');
36 }
37
38 $this->value = $dateTime;
39 }
40
41 public function getContent()
42 {
43 return $this->value;
44 }
45
46 protected function getLastDateTimeErrors()
47 {
48 $messages = '';
49 $lastErrors = DateTime::getLastErrors() ?: ['errors' => []];
50 foreach ($lastErrors['errors'] as $errorMessage) {
51 $messages .= "{$errorMessage}, ";
52 }
53
54 return substr($messages, 0, -2);
55 }
56
57 public function __toString()
58 {
59 return $this->value->format("Y-m-d\tH:i:s");
60 }
61
62 protected static function extractTimeZoneData(&$binaryData, &$offsetIndex, DateTime $dateTime)
63 {
64 $sign = $binaryData[$offsetIndex++];
65 $timeOffsetHours = intval(substr($binaryData, $offsetIndex, 2));
66 $timeOffsetMinutes = intval(substr($binaryData, $offsetIndex + 2, 2));
67 $offsetIndex += 4;
68
69 $interval = new DateInterval("PT{$timeOffsetHours}H{$timeOffsetMinutes}M");
70 if ($sign == '+') {
71 $dateTime->sub($interval);
72 } else {
73 $dateTime->add($interval);
74 }
75
76 return $dateTime;
77 }
78 }
79