@@ -2119,9 +2119,9 @@ |
||
2119 | 2119 | $props = mapi_getprops($message, $properties); |
2120 | 2120 | // Do not update timezone information if the appointment times haven't changed |
2121 | 2121 | if (!isset($action['props']['commonstart']) && |
2122 | - !isset($action['props']['commonend']) && |
|
2123 | - !isset($action['props']['startdate']) && |
|
2124 | - !isset($action['props']['enddate']) |
|
2122 | + !isset($action['props']['commonend']) && |
|
2123 | + !isset($action['props']['startdate']) && |
|
2124 | + !isset($action['props']['enddate']) |
|
2125 | 2125 | ) { |
2126 | 2126 | unset($action['props']['tzdefstart'], $action['props']['tzdefend']); |
2127 | 2127 | } |
@@ -1058,8 +1058,9 @@ discard block |
||
1058 | 1058 | */ |
1059 | 1059 | public function renameFolder($store, $entryid, $name, &$folderProps) { |
1060 | 1060 | $folder = mapi_msgstore_openentry($store, $entryid); |
1061 | - if (!$folder) |
|
1062 | - return false; |
|
1061 | + if (!$folder) { |
|
1062 | + return false; |
|
1063 | + } |
|
1063 | 1064 | $result = false; |
1064 | 1065 | $folderProps = mapi_getprops($folder, [PR_ENTRYID, PR_STORE_ENTRYID, PR_DISPLAY_NAME]); |
1065 | 1066 | /* |
@@ -2087,7 +2088,8 @@ discard block |
||
2087 | 2088 | if (!empty($action['props']['timezone_iana'])) { |
2088 | 2089 | try { |
2089 | 2090 | $tzdef = mapi_ianatz_to_tzdef($action['props']['timezone_iana']); |
2090 | - } catch (Exception $e) { |
|
2091 | + } |
|
2092 | + catch (Exception $e) { |
|
2091 | 2093 | } |
2092 | 2094 | if ($tzdef !== false) { |
2093 | 2095 | $action['props']['tzdefstart'] = $action['props']['tzdefend'] = bin2hex($tzdef); |
@@ -2610,8 +2612,9 @@ discard block |
||
2610 | 2612 | $storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_ENTRYID]); |
2611 | 2613 | $origStoreprops = mapi_getprops($origStore, [PR_ENTRYID]); |
2612 | 2614 | |
2613 | - if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) |
|
2614 | - return false; |
|
2615 | + if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) { |
|
2616 | + return false; |
|
2617 | + } |
|
2615 | 2618 | if (isset($storeprops[PR_IPM_SENTMAIL_ENTRYID])) { |
2616 | 2619 | $props[PR_SENTMAIL_ENTRYID] = $storeprops[PR_IPM_SENTMAIL_ENTRYID]; |
2617 | 2620 | } |
@@ -2778,8 +2781,9 @@ discard block |
||
2778 | 2781 | $message = $this->saveMessage($store, $entryid, $storeprops[PR_IPM_OUTBOX_ENTRYID], $props, $messageProps, $recipients, $attachments, [], $copyFromMessage, $copyAttachments, $copyRecipients, $copyInlineAttachmentsOnly, true, true, $isPlainText); |
2779 | 2782 | } |
2780 | 2783 | |
2781 | - if (!$message) |
|
2782 | - return false; |
|
2784 | + if (!$message) { |
|
2785 | + return false; |
|
2786 | + } |
|
2783 | 2787 | // Allowing to hook in just before the data sent away to be sent to the client |
2784 | 2788 | $GLOBALS['PluginManager']->triggerHook('server.core.operations.submitmessage', [ |
2785 | 2789 | 'moduleObject' => $this, |
@@ -3057,8 +3061,9 @@ discard block |
||
3057 | 3061 | |
3058 | 3062 | if (array_search(strtolower($foldername), $folderNames) !== false) { |
3059 | 3063 | $i = 2; |
3060 | - while (array_search(strtolower($foldername)." ($i)", $folderNames) !== false) |
|
3061 | - ++$i; |
|
3064 | + while (array_search(strtolower($foldername)." ($i)", $folderNames) !== false) { |
|
3065 | + ++$i; |
|
3066 | + } |
|
3062 | 3067 | $foldername .= " ($i)"; |
3063 | 3068 | } |
3064 | 3069 |
@@ -25,9 +25,11 @@ |
||
25 | 25 | * @return bool true on success or false on failure |
26 | 26 | */ |
27 | 27 | public function execute() { |
28 | - foreach ($this->data as $actionType => $actionData) try { |
|
28 | + foreach ($this->data as $actionType => $actionData) { |
|
29 | + try { |
|
29 | 30 | if (!isset($actionType)) |
30 | 31 | continue; |
32 | + } |
|
31 | 33 | switch ($actionType) { |
32 | 34 | case 'certificate': |
33 | 35 | $data = $this->verifyCertificate($actionData); |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | $messageClass = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
164 | 164 | $messageClass = $messageClass[PR_MESSAGE_CLASS]; |
165 | 165 | if ($messageClass !== 'IPM.Note.SMIME' && |
166 | - $messageClass !== 'IPM.Note.SMIME.SignedEncrypt' && |
|
167 | - $messageClass !== 'IPM.Note.deferSMIME' && |
|
168 | - $messageClass !== 'IPM.Note.deferSMIME.SignedEncrypt') |
|
166 | + $messageClass !== 'IPM.Note.SMIME.SignedEncrypt' && |
|
167 | + $messageClass !== 'IPM.Note.deferSMIME' && |
|
168 | + $messageClass !== 'IPM.Note.deferSMIME.SignedEncrypt') |
|
169 | 169 | return; |
170 | 170 | |
171 | 171 | $recipients = $data['action']['props']['smime']; |
@@ -607,17 +607,17 @@ discard block |
||
607 | 607 | if (!isset($messageClass)) |
608 | 608 | return; |
609 | 609 | if (stripos($messageClass, 'IPM.Note.deferSMIME') === false && |
610 | - stripos($messageClass, 'IPM.Note.SMIME') === false) |
|
610 | + stripos($messageClass, 'IPM.Note.SMIME') === false) |
|
611 | 611 | return; |
612 | 612 | |
613 | 613 | // FIXME: for now return when we are going to sign but we don't have the passphrase set |
614 | 614 | // This should never happen sign |
615 | 615 | $encryptionStore = \EncryptionStore::getInstance(); |
616 | 616 | if (($messageClass === 'IPM.Note.deferSMIME.SignedEncrypt' || |
617 | - $messageClass === 'IPM.Note.deferSMIME.MultipartSigned' || |
|
618 | - $messageClass === 'IPM.Note.SMIME.SignedEncrypt' || |
|
619 | - $messageClass === 'IPM.Note.SMIME.MultipartSigned') && |
|
620 | - !$encryptionStore->get('smime')) |
|
617 | + $messageClass === 'IPM.Note.deferSMIME.MultipartSigned' || |
|
618 | + $messageClass === 'IPM.Note.SMIME.SignedEncrypt' || |
|
619 | + $messageClass === 'IPM.Note.SMIME.MultipartSigned') && |
|
620 | + !$encryptionStore->get('smime')) |
|
621 | 621 | return; |
622 | 622 | // NOTE: setting message class to IPM.Note, so that mapi_inetmapi_imtoinet converts the message to plain email |
623 | 623 | // and doesn't fail when handling the attachments. |
@@ -165,8 +165,9 @@ discard block |
||
165 | 165 | if ($messageClass !== 'IPM.Note.SMIME' && |
166 | 166 | $messageClass !== 'IPM.Note.SMIME.SignedEncrypt' && |
167 | 167 | $messageClass !== 'IPM.Note.deferSMIME' && |
168 | - $messageClass !== 'IPM.Note.deferSMIME.SignedEncrypt') |
|
169 | - return; |
|
168 | + $messageClass !== 'IPM.Note.deferSMIME.SignedEncrypt') { |
|
169 | + return; |
|
170 | + } |
|
170 | 171 | |
171 | 172 | $recipients = $data['action']['props']['smime']; |
172 | 173 | $missingCerts = []; |
@@ -300,8 +301,9 @@ discard block |
||
300 | 301 | $importCert = file_get_contents($outcert); |
301 | 302 | $parsedImportCert = openssl_x509_parse($importCert); |
302 | 303 | $parsedUserCert = openssl_x509_parse($userCert); |
303 | - if (!$signed_ok || $openssl_error_code === OPENSSL_CA_VERIFY_FAIL) |
|
304 | - continue; |
|
304 | + if (!$signed_ok || $openssl_error_code === OPENSSL_CA_VERIFY_FAIL) { |
|
305 | + continue; |
|
306 | + } |
|
305 | 307 | |
306 | 308 | // CA Checks out |
307 | 309 | $caCerts = $this->extractCAs($tmpfname); |
@@ -528,8 +530,9 @@ discard block |
||
528 | 530 | * @param {mixed} $data |
529 | 531 | */ |
530 | 532 | public function onUploadCertificate($data) { |
531 | - if ($data['sourcetype'] !== 'certificate') |
|
532 | - return; |
|
533 | + if ($data['sourcetype'] !== 'certificate') { |
|
534 | + return; |
|
535 | + } |
|
533 | 536 | $passphrase = $_POST['passphrase']; |
534 | 537 | $saveCert = false; |
535 | 538 | $tmpname = $data['tmpname']; |
@@ -604,11 +607,13 @@ discard block |
||
604 | 607 | $props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
605 | 608 | $messageClass = $props[PR_MESSAGE_CLASS]; |
606 | 609 | |
607 | - if (!isset($messageClass)) |
|
608 | - return; |
|
610 | + if (!isset($messageClass)) { |
|
611 | + return; |
|
612 | + } |
|
609 | 613 | if (stripos($messageClass, 'IPM.Note.deferSMIME') === false && |
610 | - stripos($messageClass, 'IPM.Note.SMIME') === false) |
|
611 | - return; |
|
614 | + stripos($messageClass, 'IPM.Note.SMIME') === false) { |
|
615 | + return; |
|
616 | + } |
|
612 | 617 | |
613 | 618 | // FIXME: for now return when we are going to sign but we don't have the passphrase set |
614 | 619 | // This should never happen sign |
@@ -617,8 +622,9 @@ discard block |
||
617 | 622 | $messageClass === 'IPM.Note.deferSMIME.MultipartSigned' || |
618 | 623 | $messageClass === 'IPM.Note.SMIME.SignedEncrypt' || |
619 | 624 | $messageClass === 'IPM.Note.SMIME.MultipartSigned') && |
620 | - !$encryptionStore->get('smime')) |
|
621 | - return; |
|
625 | + !$encryptionStore->get('smime')) { |
|
626 | + return; |
|
627 | + } |
|
622 | 628 | // NOTE: setting message class to IPM.Note, so that mapi_inetmapi_imtoinet converts the message to plain email |
623 | 629 | // and doesn't fail when handling the attachments. |
624 | 630 | mapi_setprops($message, [PR_MESSAGE_CLASS => 'IPM.Note']); |
@@ -862,8 +868,9 @@ discard block |
||
862 | 868 | foreach ($certs as $cert) { |
863 | 869 | $pubkey = mapi_msgstore_openentry($this->getStore(), $cert[PR_ENTRYID]); |
864 | 870 | $certificate = ""; |
865 | - if ($pubkey == false) |
|
866 | - continue; |
|
871 | + if ($pubkey == false) { |
|
872 | + continue; |
|
873 | + } |
|
867 | 874 | // retrieve pkcs#11 certificate from body |
868 | 875 | $stream = mapi_openproperty($pubkey, PR_BODY, IID_IStream, 0, 0); |
869 | 876 | $stat = mapi_stream_stat($stream); |
@@ -985,8 +992,9 @@ discard block |
||
985 | 992 | */ |
986 | 993 | public function importCertificate($cert, $certData, $type = 'public', $force = false) { |
987 | 994 | $certEmail = getCertEmail($certData); |
988 | - if ($this->pubcertExists($certEmail) && !$force && $type !== 'private') |
|
989 | - return; |
|
995 | + if ($this->pubcertExists($certEmail) && !$force && $type !== 'private') { |
|
996 | + return; |
|
997 | + } |
|
990 | 998 | $issued_by = ""; |
991 | 999 | foreach (array_keys($certData['issuer']) as $key) { |
992 | 1000 | $issued_by .= $key . '=' . $certData['issuer'][$key] . "\n"; |
@@ -1110,8 +1118,9 @@ discard block |
||
1110 | 1118 | * @return array with properties |
1111 | 1119 | */ |
1112 | 1120 | public function getSenderAddress($mapiMessage) { |
1113 | - if (method_exists($GLOBALS['operations'], 'getSenderAddress')) |
|
1114 | - return $GLOBALS["operations"]->getSenderAddress($mapiMessage); |
|
1121 | + if (method_exists($GLOBALS['operations'], 'getSenderAddress')) { |
|
1122 | + return $GLOBALS["operations"]->getSenderAddress($mapiMessage); |
|
1123 | + } |
|
1115 | 1124 | |
1116 | 1125 | $messageProps = mapi_getprops($mapiMessage, [PR_SENT_REPRESENTING_ENTRYID, PR_SENDER_ENTRYID]); |
1117 | 1126 | $senderEntryID = isset($messageProps[PR_SENT_REPRESENTING_ENTRYID]) ? $messageProps[PR_SENT_REPRESENTING_ENTRYID] : $messageProps[PR_SENDER_ENTRYID]; |
@@ -98,8 +98,9 @@ |
||
98 | 98 | // Get messages from certificates |
99 | 99 | foreach ($privateCerts as $privateCert) { |
100 | 100 | $privateCertMessage = mapi_msgstore_openentry($store, $privateCert[PR_ENTRYID]); |
101 | - if ($privateCertMessage === false) |
|
102 | - continue; |
|
101 | + if ($privateCertMessage === false) { |
|
102 | + continue; |
|
103 | + } |
|
103 | 104 | $pkcs12 = ""; |
104 | 105 | $certs = []; |
105 | 106 | // Read pkcs12 cert from message |
@@ -376,8 +376,9 @@ discard block |
||
376 | 376 | |
377 | 377 | // Compare the timezone definitions of the client and the appointment. |
378 | 378 | // Further processing is only required if they don't match. |
379 | - if ($GLOBALS['entryid']->compareEntryIds($this->tzdef, $calendaritem['props']['tzdefstart'])) |
|
380 | - return; |
|
379 | + if ($GLOBALS['entryid']->compareEntryIds($this->tzdef, $calendaritem['props']['tzdefstart'])) { |
|
380 | + return; |
|
381 | + } |
|
381 | 382 | |
382 | 383 | if ($this->tzdefObj === false) { |
383 | 384 | $this->tzdefObj = $GLOBALS['entryid']->createTimezoneDefinitionObject($this->tzdef); |
@@ -389,8 +390,9 @@ discard block |
||
389 | 390 | // Find TZRULE_FLAG_EFFECTIVE_TZREG rule for the appointment's timezone |
390 | 391 | $appTzEffRuleIdx = getEffectiveTzreg($appTzDefStart['rules']); |
391 | 392 | |
392 | - if (is_null($this->tzEffRuleIdx) && !is_null($appTzEffRuleIdx)) |
|
393 | - return; |
|
393 | + if (is_null($this->tzEffRuleIdx) && !is_null($appTzEffRuleIdx)) { |
|
394 | + return; |
|
395 | + } |
|
394 | 396 | // first apply the bias of the appointment timezone and the bias of the browser |
395 | 397 | $localStart = $calendaritem['props']['startdate'] - $appTzDefStart['rules'][$appTzEffRuleIdx]['bias'] * 60 + $this->tzdefObj['rules'][$this->tzEffRuleIdx]['bias'] * 60; |
396 | 398 | if (isDst($appTzDefStart['rules'][$appTzEffRuleIdx], $calendaritem['props']['startdate'])) { |
@@ -21,17 +21,17 @@ |
||
21 | 21 | */ |
22 | 22 | class PhpfastcacheIOException extends PhpfastcacheCoreException |
23 | 23 | { |
24 | - /** |
|
25 | - * @inheritdoc |
|
26 | - */ |
|
27 | - public function __construct(string $message = "", int $code = 0, \Throwable $previous = null) |
|
28 | - { |
|
29 | - $lastError = error_get_last(); |
|
30 | - if ($lastError) { |
|
31 | - $message .= "\n"; |
|
32 | - $message .= "Additional information provided by error_get_last():\n"; |
|
33 | - $message .= "{$lastError['message']} in {$lastError['file']} line {$lastError['line']}"; |
|
34 | - } |
|
35 | - parent::__construct($message, $code, $previous); |
|
36 | - } |
|
24 | + /** |
|
25 | + * @inheritdoc |
|
26 | + */ |
|
27 | + public function __construct(string $message = "", int $code = 0, \Throwable $previous = null) |
|
28 | + { |
|
29 | + $lastError = error_get_last(); |
|
30 | + if ($lastError) { |
|
31 | + $message .= "\n"; |
|
32 | + $message .= "Additional information provided by error_get_last():\n"; |
|
33 | + $message .= "{$lastError['message']} in {$lastError['file']} line {$lastError['line']}"; |
|
34 | + } |
|
35 | + parent::__construct($message, $code, $previous); |
|
36 | + } |
|
37 | 37 | } |
@@ -24,8 +24,7 @@ |
||
24 | 24 | /** |
25 | 25 | * @inheritdoc |
26 | 26 | */ |
27 | - public function __construct(string $message = "", int $code = 0, \Throwable $previous = null) |
|
28 | - { |
|
27 | + public function __construct(string $message = "", int $code = 0, \Throwable $previous = null) { |
|
29 | 28 | $lastError = error_get_last(); |
30 | 29 | if ($lastError) { |
31 | 30 | $message .= "\n"; |
@@ -18,12 +18,12 @@ |
||
18 | 18 | |
19 | 19 | class PhpfastcacheCorruptedDataException extends PhpfastcacheDriverException |
20 | 20 | { |
21 | - /** |
|
22 | - * @param string $message |
|
23 | - * @param mixed|null $corruptedData |
|
24 | - */ |
|
25 | - public function __construct(protected $message = '', protected mixed $corruptedData = null) |
|
26 | - { |
|
27 | - parent::__construct($message); |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param string $message |
|
23 | + * @param mixed|null $corruptedData |
|
24 | + */ |
|
25 | + public function __construct(protected $message = '', protected mixed $corruptedData = null) |
|
26 | + { |
|
27 | + parent::__construct($message); |
|
28 | + } |
|
29 | 29 | } |
@@ -22,8 +22,7 @@ |
||
22 | 22 | * @param string $message |
23 | 23 | * @param mixed|null $corruptedData |
24 | 24 | */ |
25 | - public function __construct(protected $message = '', protected mixed $corruptedData = null) |
|
26 | - { |
|
25 | + public function __construct(protected $message = '', protected mixed $corruptedData = null) { |
|
27 | 26 | parent::__construct($message); |
28 | 27 | } |
29 | 28 | } |
@@ -26,137 +26,137 @@ |
||
26 | 26 | */ |
27 | 27 | class Api |
28 | 28 | { |
29 | - use UninstanciableObjectTrait; |
|
30 | - |
|
31 | - protected static string $version = '4.3.0'; |
|
32 | - |
|
33 | - /** |
|
34 | - * This method will return the current |
|
35 | - * API version, the API version will be |
|
36 | - * updated by following the semantic versioning |
|
37 | - * based on changes of: |
|
38 | - * - ExtendedCacheItemPoolInterface |
|
39 | - * - ExtendedCacheItemInterface |
|
40 | - * - AggregatablePoolInterface |
|
41 | - * - AggregatorInterface |
|
42 | - * - ClusterPoolInterface |
|
43 | - * - EventManagerInterface |
|
44 | - * |
|
45 | - * @see https://semver.org/ |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function getVersion(): string |
|
49 | - { |
|
50 | - return self::$version; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param bool $fallbackOnChangelog |
|
55 | - * @param bool $cacheable |
|
56 | - * @return string |
|
57 | - * @throws PhpfastcacheLogicException |
|
58 | - * @throws PhpfastcacheIOException |
|
59 | - */ |
|
60 | - public static function getPhpfastcacheVersion(bool $fallbackOnChangelog = true, bool $cacheable = true): string |
|
61 | - { |
|
62 | - /** |
|
63 | - * Cache the version statically to improve |
|
64 | - * performances on multiple calls |
|
65 | - */ |
|
66 | - static $version; |
|
67 | - |
|
68 | - if ($version && $cacheable) { |
|
69 | - return $version; |
|
70 | - } |
|
71 | - |
|
72 | - if (\function_exists('shell_exec')) { |
|
73 | - $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags ' . (DIRECTORY_SEPARATOR === '\\' ? '2>nul' : '2>/dev/null'); |
|
74 | - $stdout = \shell_exec($command); |
|
75 | - if (\is_string($stdout)) { |
|
76 | - return trim($stdout); |
|
77 | - } |
|
78 | - if (!$fallbackOnChangelog) { |
|
79 | - throw new PhpfastcacheLogicException('The git command used to retrieve the Phpfastcache version has failed.'); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - if (!$fallbackOnChangelog) { |
|
84 | - throw new PhpfastcacheLogicException('shell_exec is disabled therefore the Phpfastcache version cannot be retrieved.'); |
|
85 | - } |
|
86 | - |
|
87 | - $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
|
88 | - if (\file_exists($changelogFilename)) { |
|
89 | - $semverRegexp = '/^([\d]+)\.([\d]+)\.([\d]+)(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+[\dA-Za-z-]+)?$/'; |
|
90 | - $changelog = \explode("\n", self::getPhpfastcacheChangelog()); |
|
91 | - foreach ($changelog as $line) { |
|
92 | - $trimmedLine = \trim($line, " \t\n\r\0\x0B#"); |
|
93 | - if (\str_starts_with($line, '#') && \preg_match($semverRegexp, $trimmedLine)) { |
|
94 | - return $trimmedLine; |
|
95 | - } |
|
96 | - } |
|
97 | - throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache version through the CHANGELOG.md as no valid string were found in it.'); |
|
98 | - } |
|
99 | - throw new PhpfastcacheLogicException( |
|
100 | - 'shell_exec being disabled we attempted to retrieve the Phpfastcache version through the CHANGELOG.md file but it is not readable or has been removed.' |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Return the Phpfastcache changelog, as a string. |
|
106 | - * @return string |
|
107 | - * @throws PhpfastcacheLogicException |
|
108 | - * @throws PhpfastcacheIOException |
|
109 | - */ |
|
110 | - public static function getPhpfastcacheChangelog(): string |
|
111 | - { |
|
112 | - $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
|
113 | - if (\file_exists($changelogFilename)) { |
|
114 | - $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
|
115 | - if ($string) { |
|
116 | - return $string; |
|
117 | - } |
|
118 | - throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache changelog as it seems to be empty.'); |
|
119 | - } |
|
120 | - throw new PhpfastcacheIOException('The CHANGELOG.md file is not readable or has been removed.'); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param bool $cacheable |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function getPhpfastcacheGitHeadHash(bool $cacheable = true): string |
|
128 | - { |
|
129 | - static $hash; |
|
130 | - |
|
131 | - if ($hash && $cacheable) { |
|
132 | - return $hash; |
|
133 | - } |
|
134 | - |
|
135 | - if (\function_exists('shell_exec')) { |
|
136 | - $stdout = \shell_exec('git rev-parse --short HEAD ' . (DIRECTORY_SEPARATOR === '\\' ? '2>nul' : '2>/dev/null')); |
|
137 | - if (\is_string($stdout)) { |
|
138 | - return '#' . \trim($stdout); |
|
139 | - } |
|
140 | - } |
|
141 | - return ''; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Return the API changelog, as a string. |
|
146 | - * @return string |
|
147 | - * @throws PhpfastcacheLogicException |
|
148 | - * @throws PhpfastcacheIOException |
|
149 | - */ |
|
150 | - public static function getChangelog(): string |
|
151 | - { |
|
152 | - $changelogFilename = __DIR__ . '/../../CHANGELOG_API.md'; |
|
153 | - if (\file_exists($changelogFilename)) { |
|
154 | - $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
|
155 | - if ($string) { |
|
156 | - return $string; |
|
157 | - } |
|
158 | - throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache API changelog as it seems to be empty.'); |
|
159 | - } |
|
160 | - throw new PhpfastcacheIOException('The CHANGELOG_API.md file is not readable or has been removed.'); |
|
161 | - } |
|
29 | + use UninstanciableObjectTrait; |
|
30 | + |
|
31 | + protected static string $version = '4.3.0'; |
|
32 | + |
|
33 | + /** |
|
34 | + * This method will return the current |
|
35 | + * API version, the API version will be |
|
36 | + * updated by following the semantic versioning |
|
37 | + * based on changes of: |
|
38 | + * - ExtendedCacheItemPoolInterface |
|
39 | + * - ExtendedCacheItemInterface |
|
40 | + * - AggregatablePoolInterface |
|
41 | + * - AggregatorInterface |
|
42 | + * - ClusterPoolInterface |
|
43 | + * - EventManagerInterface |
|
44 | + * |
|
45 | + * @see https://semver.org/ |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function getVersion(): string |
|
49 | + { |
|
50 | + return self::$version; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param bool $fallbackOnChangelog |
|
55 | + * @param bool $cacheable |
|
56 | + * @return string |
|
57 | + * @throws PhpfastcacheLogicException |
|
58 | + * @throws PhpfastcacheIOException |
|
59 | + */ |
|
60 | + public static function getPhpfastcacheVersion(bool $fallbackOnChangelog = true, bool $cacheable = true): string |
|
61 | + { |
|
62 | + /** |
|
63 | + * Cache the version statically to improve |
|
64 | + * performances on multiple calls |
|
65 | + */ |
|
66 | + static $version; |
|
67 | + |
|
68 | + if ($version && $cacheable) { |
|
69 | + return $version; |
|
70 | + } |
|
71 | + |
|
72 | + if (\function_exists('shell_exec')) { |
|
73 | + $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags ' . (DIRECTORY_SEPARATOR === '\\' ? '2>nul' : '2>/dev/null'); |
|
74 | + $stdout = \shell_exec($command); |
|
75 | + if (\is_string($stdout)) { |
|
76 | + return trim($stdout); |
|
77 | + } |
|
78 | + if (!$fallbackOnChangelog) { |
|
79 | + throw new PhpfastcacheLogicException('The git command used to retrieve the Phpfastcache version has failed.'); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + if (!$fallbackOnChangelog) { |
|
84 | + throw new PhpfastcacheLogicException('shell_exec is disabled therefore the Phpfastcache version cannot be retrieved.'); |
|
85 | + } |
|
86 | + |
|
87 | + $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
|
88 | + if (\file_exists($changelogFilename)) { |
|
89 | + $semverRegexp = '/^([\d]+)\.([\d]+)\.([\d]+)(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+[\dA-Za-z-]+)?$/'; |
|
90 | + $changelog = \explode("\n", self::getPhpfastcacheChangelog()); |
|
91 | + foreach ($changelog as $line) { |
|
92 | + $trimmedLine = \trim($line, " \t\n\r\0\x0B#"); |
|
93 | + if (\str_starts_with($line, '#') && \preg_match($semverRegexp, $trimmedLine)) { |
|
94 | + return $trimmedLine; |
|
95 | + } |
|
96 | + } |
|
97 | + throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache version through the CHANGELOG.md as no valid string were found in it.'); |
|
98 | + } |
|
99 | + throw new PhpfastcacheLogicException( |
|
100 | + 'shell_exec being disabled we attempted to retrieve the Phpfastcache version through the CHANGELOG.md file but it is not readable or has been removed.' |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Return the Phpfastcache changelog, as a string. |
|
106 | + * @return string |
|
107 | + * @throws PhpfastcacheLogicException |
|
108 | + * @throws PhpfastcacheIOException |
|
109 | + */ |
|
110 | + public static function getPhpfastcacheChangelog(): string |
|
111 | + { |
|
112 | + $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
|
113 | + if (\file_exists($changelogFilename)) { |
|
114 | + $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
|
115 | + if ($string) { |
|
116 | + return $string; |
|
117 | + } |
|
118 | + throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache changelog as it seems to be empty.'); |
|
119 | + } |
|
120 | + throw new PhpfastcacheIOException('The CHANGELOG.md file is not readable or has been removed.'); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param bool $cacheable |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function getPhpfastcacheGitHeadHash(bool $cacheable = true): string |
|
128 | + { |
|
129 | + static $hash; |
|
130 | + |
|
131 | + if ($hash && $cacheable) { |
|
132 | + return $hash; |
|
133 | + } |
|
134 | + |
|
135 | + if (\function_exists('shell_exec')) { |
|
136 | + $stdout = \shell_exec('git rev-parse --short HEAD ' . (DIRECTORY_SEPARATOR === '\\' ? '2>nul' : '2>/dev/null')); |
|
137 | + if (\is_string($stdout)) { |
|
138 | + return '#' . \trim($stdout); |
|
139 | + } |
|
140 | + } |
|
141 | + return ''; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Return the API changelog, as a string. |
|
146 | + * @return string |
|
147 | + * @throws PhpfastcacheLogicException |
|
148 | + * @throws PhpfastcacheIOException |
|
149 | + */ |
|
150 | + public static function getChangelog(): string |
|
151 | + { |
|
152 | + $changelogFilename = __DIR__ . '/../../CHANGELOG_API.md'; |
|
153 | + if (\file_exists($changelogFilename)) { |
|
154 | + $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
|
155 | + if ($string) { |
|
156 | + return $string; |
|
157 | + } |
|
158 | + throw new PhpfastcacheLogicException('Unable to retrieve the Phpfastcache API changelog as it seems to be empty.'); |
|
159 | + } |
|
160 | + throw new PhpfastcacheIOException('The CHANGELOG_API.md file is not readable or has been removed.'); |
|
161 | + } |
|
162 | 162 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | class Wiki |
22 | 22 | { |
23 | - use UninstanciableObjectTrait; |
|
23 | + use UninstanciableObjectTrait; |
|
24 | 24 | |
25 | - public const FETCH_ALL_KEY_URL = 'https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys'; |
|
25 | + public const FETCH_ALL_KEY_URL = 'https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys'; |
|
26 | 26 | } |