@@ -45,37 +45,37 @@ |
||
45 | 45 | |
46 | 46 | case 'server.index.load.custom': |
47 | 47 | switch ($data['name']) { |
48 | - case 'files_get_recipients': |
|
49 | - RecipientHandler::doGetRecipients(); |
|
50 | - break; |
|
48 | + case 'files_get_recipients': |
|
49 | + RecipientHandler::doGetRecipients(); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'download_file': |
|
53 | - DownloadHandler::doDownload(); |
|
54 | - break; |
|
52 | + case 'download_file': |
|
53 | + DownloadHandler::doDownload(); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'upload_file': |
|
57 | - UploadHandler::doUpload(); |
|
58 | - break; |
|
56 | + case 'upload_file': |
|
57 | + UploadHandler::doUpload(); |
|
58 | + break; |
|
59 | 59 | |
60 | - case 'form': |
|
61 | - if (isset($_GET['backend'])) { |
|
62 | - $backend = urldecode($_GET["backend"]); |
|
63 | - } |
|
64 | - else { |
|
65 | - $backend = ''; |
|
66 | - } |
|
67 | - $backendstore = Files\Backend\BackendStore::getInstance(); |
|
60 | + case 'form': |
|
61 | + if (isset($_GET['backend'])) { |
|
62 | + $backend = urldecode($_GET["backend"]); |
|
63 | + } |
|
64 | + else { |
|
65 | + $backend = ''; |
|
66 | + } |
|
67 | + $backendstore = Files\Backend\BackendStore::getInstance(); |
|
68 | 68 | |
69 | - if ($backendstore->backendExists($backend)) { |
|
70 | - $backendInstance = $backendstore->getInstanceOfBackend($backend); |
|
71 | - $formdata = $backendInstance->getFormConfig(); |
|
69 | + if ($backendstore->backendExists($backend)) { |
|
70 | + $backendInstance = $backendstore->getInstanceOfBackend($backend); |
|
71 | + $formdata = $backendInstance->getFormConfig(); |
|
72 | 72 | |
73 | - exit($formdata); |
|
74 | - } |
|
73 | + exit($formdata); |
|
74 | + } |
|
75 | 75 | |
76 | - exit("Specified backend does not exist!"); |
|
76 | + exit("Specified backend does not exist!"); |
|
77 | 77 | |
78 | - break; |
|
78 | + break; |
|
79 | 79 | } |
80 | 80 | break; |
81 | 81 | } |
@@ -15,31 +15,31 @@ |
||
15 | 15 | $tag = $this->peek(); |
16 | 16 | |
17 | 17 | switch ($tag) { |
18 | - case 0: |
|
19 | - $res['otherName'] = $this->oid(-6); |
|
20 | - break; |
|
21 | - |
|
22 | - case 1: |
|
23 | - $res['rfc822Name'] = $this->next(-22); |
|
24 | - break; |
|
25 | - |
|
26 | - case 2: |
|
27 | - $res['dNSName'] = $this->next(-22); |
|
28 | - break; |
|
29 | - |
|
30 | - case 4: |
|
31 | - $this->next(4); |
|
32 | - $res['directoryName'] = $this->name(); |
|
33 | - $res['directoryName_'] = $this->nameasstring($res['directoryName']); |
|
34 | - break; |
|
35 | - |
|
36 | - case 6: |
|
37 | - $res['uniformResourceIdentifier'] = $this->next(-22); |
|
38 | - break; |
|
39 | - |
|
40 | - default: |
|
41 | - throw new \Exception("Unsupported GeneralName: {$tag}"); |
|
42 | -# trigger_error("Unsupported GeneralName: $tag", E_USER_ERROR); |
|
18 | + case 0: |
|
19 | + $res['otherName'] = $this->oid(-6); |
|
20 | + break; |
|
21 | + |
|
22 | + case 1: |
|
23 | + $res['rfc822Name'] = $this->next(-22); |
|
24 | + break; |
|
25 | + |
|
26 | + case 2: |
|
27 | + $res['dNSName'] = $this->next(-22); |
|
28 | + break; |
|
29 | + |
|
30 | + case 4: |
|
31 | + $this->next(4); |
|
32 | + $res['directoryName'] = $this->name(); |
|
33 | + $res['directoryName_'] = $this->nameasstring($res['directoryName']); |
|
34 | + break; |
|
35 | + |
|
36 | + case 6: |
|
37 | + $res['uniformResourceIdentifier'] = $this->next(-22); |
|
38 | + break; |
|
39 | + |
|
40 | + default: |
|
41 | + throw new \Exception("Unsupported GeneralName: {$tag}"); |
|
42 | + # trigger_error("Unsupported GeneralName: $tag", E_USER_ERROR); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $res; |
@@ -29,62 +29,62 @@ |
||
29 | 29 | if (!isset($actionType)) |
30 | 30 | continue; |
31 | 31 | switch ($actionType) { |
32 | - case 'certificate': |
|
33 | - $data = $this->verifyCertificate($actionData); |
|
34 | - $response = [ |
|
35 | - 'type' => 3, |
|
36 | - 'status' => $data['status'], |
|
37 | - 'message' => $data['message'], |
|
38 | - 'data' => $data['data'], |
|
39 | - ]; |
|
40 | - $this->addActionData('certificate', $response); |
|
41 | - $GLOBALS['bus']->addData($this->getResponseData()); |
|
42 | - break; |
|
32 | + case 'certificate': |
|
33 | + $data = $this->verifyCertificate($actionData); |
|
34 | + $response = [ |
|
35 | + 'type' => 3, |
|
36 | + 'status' => $data['status'], |
|
37 | + 'message' => $data['message'], |
|
38 | + 'data' => $data['data'], |
|
39 | + ]; |
|
40 | + $this->addActionData('certificate', $response); |
|
41 | + $GLOBALS['bus']->addData($this->getResponseData()); |
|
42 | + break; |
|
43 | 43 | |
44 | - case 'passphrase': |
|
45 | - $data = $this->verifyPassphrase($actionData); |
|
46 | - $response = [ |
|
47 | - 'type' => 3, |
|
48 | - 'status' => $data['status'], |
|
49 | - ]; |
|
50 | - $this->addActionData('passphrase', $response); |
|
51 | - $GLOBALS['bus']->addData($this->getResponseData()); |
|
52 | - break; |
|
44 | + case 'passphrase': |
|
45 | + $data = $this->verifyPassphrase($actionData); |
|
46 | + $response = [ |
|
47 | + 'type' => 3, |
|
48 | + 'status' => $data['status'], |
|
49 | + ]; |
|
50 | + $this->addActionData('passphrase', $response); |
|
51 | + $GLOBALS['bus']->addData($this->getResponseData()); |
|
52 | + break; |
|
53 | 53 | |
54 | - case 'changepassphrase': |
|
55 | - $data = $this->changePassphrase($actionData); |
|
56 | - if ($data === CHANGE_PASSPHRASE_SUCCESS) { |
|
57 | - // Reset cached passphrase. |
|
58 | - $encryptionStore = EncryptionStore::getInstance(); |
|
59 | - withPHPSession(function () use ($encryptionStore) { |
|
60 | - $encryptionStore->add('smime', ''); |
|
61 | - }); |
|
62 | - } |
|
63 | - $response = [ |
|
64 | - 'type' => 3, |
|
65 | - 'code' => $data, |
|
66 | - ]; |
|
67 | - $this->addActionData('changepassphrase', $response); |
|
68 | - $GLOBALS['bus']->addData($this->getResponseData()); |
|
69 | - break; |
|
54 | + case 'changepassphrase': |
|
55 | + $data = $this->changePassphrase($actionData); |
|
56 | + if ($data === CHANGE_PASSPHRASE_SUCCESS) { |
|
57 | + // Reset cached passphrase. |
|
58 | + $encryptionStore = EncryptionStore::getInstance(); |
|
59 | + withPHPSession(function () use ($encryptionStore) { |
|
60 | + $encryptionStore->add('smime', ''); |
|
61 | + }); |
|
62 | + } |
|
63 | + $response = [ |
|
64 | + 'type' => 3, |
|
65 | + 'code' => $data, |
|
66 | + ]; |
|
67 | + $this->addActionData('changepassphrase', $response); |
|
68 | + $GLOBALS['bus']->addData($this->getResponseData()); |
|
69 | + break; |
|
70 | 70 | |
71 | - case 'list': |
|
72 | - $data = $this->getPublicCertificates(); |
|
73 | - $this->addActionData('list', $data); |
|
74 | - $GLOBALS['bus']->addData($this->getResponseData()); |
|
75 | - break; |
|
71 | + case 'list': |
|
72 | + $data = $this->getPublicCertificates(); |
|
73 | + $this->addActionData('list', $data); |
|
74 | + $GLOBALS['bus']->addData($this->getResponseData()); |
|
75 | + break; |
|
76 | 76 | |
77 | - case 'delete': |
|
78 | - // FIXME: handle multiple deletes? Separate function? |
|
79 | - $entryid = $actionData['entryid']; |
|
80 | - $root = mapi_msgstore_openentry($this->store, null); |
|
81 | - mapi_folder_deletemessages($root, [hex2bin($entryid)]); |
|
77 | + case 'delete': |
|
78 | + // FIXME: handle multiple deletes? Separate function? |
|
79 | + $entryid = $actionData['entryid']; |
|
80 | + $root = mapi_msgstore_openentry($this->store, null); |
|
81 | + mapi_folder_deletemessages($root, [hex2bin($entryid)]); |
|
82 | 82 | |
83 | - $this->sendFeedback(true); |
|
84 | - break; |
|
83 | + $this->sendFeedback(true); |
|
84 | + break; |
|
85 | 85 | |
86 | - default: |
|
87 | - $this->handleUnknownActionType($actionType); |
|
86 | + default: |
|
87 | + $this->handleUnknownActionType($actionType); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | catch (Exception $e) { |
@@ -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. |
@@ -92,45 +92,45 @@ discard block |
||
92 | 92 | public function execute($eventID, &$data) { |
93 | 93 | switch ($eventID) { |
94 | 94 | // Register plugin |
95 | - case 'server.core.settings.init.before': |
|
96 | - $this->onBeforeSettingsInit($data); |
|
97 | - break; |
|
98 | - // Verify a signed or encrypted message when an email is opened |
|
99 | - case 'server.util.parse_smime.signed': |
|
100 | - $this->onSignedMessage($data); |
|
101 | - break; |
|
102 | - |
|
103 | - case 'server.util.parse_smime.encrypted': |
|
104 | - $this->onEncrypted($data); |
|
105 | - break; |
|
106 | - // Add S/MIME property, which is send to the client |
|
107 | - case 'server.module.itemmodule.open.after': |
|
108 | - $this->onAfterOpen($data); |
|
109 | - break; |
|
110 | - // Catch uploaded certificate |
|
111 | - case 'server.upload_attachment.upload': |
|
112 | - $this->onUploadCertificate($data); |
|
113 | - break; |
|
114 | - // Sign email before sending |
|
115 | - case 'server.core.operations.submitmessage': |
|
116 | - $this->onBeforeSend($data); |
|
117 | - break; |
|
118 | - // Verify that we have public certificates for all recipients |
|
119 | - case 'server.module.createmailitemmodule.beforesend': |
|
120 | - $this->onCertificateCheck($data); |
|
121 | - break; |
|
122 | - |
|
123 | - case 'server.index.load.custom': |
|
124 | - if ($data['name'] === 'smime_passphrase') { |
|
125 | - include 'templates/passphrase.tpl.php'; |
|
126 | - exit(); |
|
127 | - } |
|
128 | - if ($data['name'] === 'smime_passphrasecheck') { |
|
129 | - // No need to do anything, this is just used to trigger |
|
130 | - // the browser's autofill save password dialog. |
|
131 | - exit(); |
|
132 | - } |
|
133 | - break; |
|
95 | + case 'server.core.settings.init.before': |
|
96 | + $this->onBeforeSettingsInit($data); |
|
97 | + break; |
|
98 | + // Verify a signed or encrypted message when an email is opened |
|
99 | + case 'server.util.parse_smime.signed': |
|
100 | + $this->onSignedMessage($data); |
|
101 | + break; |
|
102 | + |
|
103 | + case 'server.util.parse_smime.encrypted': |
|
104 | + $this->onEncrypted($data); |
|
105 | + break; |
|
106 | + // Add S/MIME property, which is send to the client |
|
107 | + case 'server.module.itemmodule.open.after': |
|
108 | + $this->onAfterOpen($data); |
|
109 | + break; |
|
110 | + // Catch uploaded certificate |
|
111 | + case 'server.upload_attachment.upload': |
|
112 | + $this->onUploadCertificate($data); |
|
113 | + break; |
|
114 | + // Sign email before sending |
|
115 | + case 'server.core.operations.submitmessage': |
|
116 | + $this->onBeforeSend($data); |
|
117 | + break; |
|
118 | + // Verify that we have public certificates for all recipients |
|
119 | + case 'server.module.createmailitemmodule.beforesend': |
|
120 | + $this->onCertificateCheck($data); |
|
121 | + break; |
|
122 | + |
|
123 | + case 'server.index.load.custom': |
|
124 | + if ($data['name'] === 'smime_passphrase') { |
|
125 | + include 'templates/passphrase.tpl.php'; |
|
126 | + exit(); |
|
127 | + } |
|
128 | + if ($data['name'] === 'smime_passphrasecheck') { |
|
129 | + // No need to do anything, this is just used to trigger |
|
130 | + // the browser's autofill save password dialog. |
|
131 | + exit(); |
|
132 | + } |
|
133 | + break; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -663,23 +663,23 @@ discard block |
||
663 | 663 | |
664 | 664 | // Sign then Encrypt email |
665 | 665 | switch ($messageClass) { |
666 | - case 'IPM.Note.deferSMIME.SignedEncrypt': |
|
667 | - case 'IPM.Note.SMIME.SignedEncrypt': |
|
668 | - $tmpFile = tempnam(sys_get_temp_dir(), true); |
|
669 | - $this->sign($tmpSendEmail, $tmpFile, $message, $signedAttach, $smimeProps); |
|
670 | - $this->encrypt($tmpFile, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
671 | - unlink($tmpFile); |
|
672 | - break; |
|
673 | - |
|
674 | - case 'IPM.Note.deferSMIME.MultipartSigned': |
|
675 | - case 'IPM.Note.SMIME.MultipartSigned': |
|
676 | - $this->sign($tmpSendEmail, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
677 | - break; |
|
678 | - |
|
679 | - case 'IPM.Note.deferSMIME': |
|
680 | - case 'IPM.Note.SMIME': |
|
681 | - $this->encrypt($tmpSendEmail, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
682 | - break; |
|
666 | + case 'IPM.Note.deferSMIME.SignedEncrypt': |
|
667 | + case 'IPM.Note.SMIME.SignedEncrypt': |
|
668 | + $tmpFile = tempnam(sys_get_temp_dir(), true); |
|
669 | + $this->sign($tmpSendEmail, $tmpFile, $message, $signedAttach, $smimeProps); |
|
670 | + $this->encrypt($tmpFile, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
671 | + unlink($tmpFile); |
|
672 | + break; |
|
673 | + |
|
674 | + case 'IPM.Note.deferSMIME.MultipartSigned': |
|
675 | + case 'IPM.Note.SMIME.MultipartSigned': |
|
676 | + $this->sign($tmpSendEmail, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
677 | + break; |
|
678 | + |
|
679 | + case 'IPM.Note.deferSMIME': |
|
680 | + case 'IPM.Note.SMIME': |
|
681 | + $this->encrypt($tmpSendEmail, $tmpSendSmimeEmail, $message, $signedAttach, $smimeProps); |
|
682 | + break; |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // Save the signed message as attachment of the send email |
@@ -33,14 +33,14 @@ |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | switch ($this->status) { |
36 | - case 'good': |
|
37 | - return OCSP_CERT_STATUS_GOOD; |
|
36 | + case 'good': |
|
37 | + return OCSP_CERT_STATUS_GOOD; |
|
38 | 38 | |
39 | - case 'revoked': |
|
40 | - return OCSP_CERT_STATUS_REVOKED; |
|
39 | + case 'revoked': |
|
40 | + return OCSP_CERT_STATUS_REVOKED; |
|
41 | 41 | |
42 | - default: |
|
43 | - return OCSP_CERT_STATUS_UNKOWN; |
|
42 | + default: |
|
43 | + return OCSP_CERT_STATUS_UNKOWN; |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |