@@ -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. |
@@ -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 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -30,85 +30,85 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Driver implements ExtendedCacheItemPoolInterface |
| 32 | 32 | { |
| 33 | - use TaggableCacheItemPoolTrait; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - public function driverCheck(): bool |
|
| 39 | - { |
|
| 40 | - return true; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return DriverStatistic |
|
| 45 | - */ |
|
| 46 | - public function getStats(): DriverStatistic |
|
| 47 | - { |
|
| 48 | - $stat = new DriverStatistic(); |
|
| 49 | - $stat->setInfo('[Devrandom] A void info string') |
|
| 50 | - ->setSize(0) |
|
| 51 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 52 | - ->setRawData(false); |
|
| 53 | - |
|
| 54 | - return $stat; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param ExtendedCacheItemInterface $item |
|
| 59 | - * @return bool |
|
| 60 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 61 | - */ |
|
| 62 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 63 | - { |
|
| 64 | - |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param ExtendedCacheItemInterface $item |
|
| 70 | - * @return ?array<string, mixed> |
|
| 71 | - * @throws \Exception |
|
| 72 | - */ |
|
| 73 | - protected function driverRead(CacheItemInterface $item): ?array |
|
| 74 | - { |
|
| 75 | - $chanceOfRetrieval = $this->getConfig()->getChanceOfRetrieval(); |
|
| 76 | - $ttl = $this->getConfig()->getDefaultTtl(); |
|
| 77 | - |
|
| 78 | - if (\random_int(0, 100) < $chanceOfRetrieval) { |
|
| 79 | - return [ |
|
| 80 | - self::DRIVER_DATA_WRAPPER_INDEX => \bin2hex(\random_bytes($this->getConfig()->getDataLength())), |
|
| 81 | - self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
| 82 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new DateTime())->add(new DateInterval("PT{$ttl}S")), |
|
| 83 | - ]; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string $key |
|
| 91 | - * @param string $encodedKey |
|
| 92 | - * @return bool |
|
| 93 | - */ |
|
| 94 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
| 95 | - { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - protected function driverClear(): bool |
|
| 103 | - { |
|
| 104 | - return true; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - protected function driverConnect(): bool |
|
| 111 | - { |
|
| 112 | - return true; |
|
| 113 | - } |
|
| 33 | + use TaggableCacheItemPoolTrait; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + public function driverCheck(): bool |
|
| 39 | + { |
|
| 40 | + return true; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return DriverStatistic |
|
| 45 | + */ |
|
| 46 | + public function getStats(): DriverStatistic |
|
| 47 | + { |
|
| 48 | + $stat = new DriverStatistic(); |
|
| 49 | + $stat->setInfo('[Devrandom] A void info string') |
|
| 50 | + ->setSize(0) |
|
| 51 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 52 | + ->setRawData(false); |
|
| 53 | + |
|
| 54 | + return $stat; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param ExtendedCacheItemInterface $item |
|
| 59 | + * @return bool |
|
| 60 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 61 | + */ |
|
| 62 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 63 | + { |
|
| 64 | + |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param ExtendedCacheItemInterface $item |
|
| 70 | + * @return ?array<string, mixed> |
|
| 71 | + * @throws \Exception |
|
| 72 | + */ |
|
| 73 | + protected function driverRead(CacheItemInterface $item): ?array |
|
| 74 | + { |
|
| 75 | + $chanceOfRetrieval = $this->getConfig()->getChanceOfRetrieval(); |
|
| 76 | + $ttl = $this->getConfig()->getDefaultTtl(); |
|
| 77 | + |
|
| 78 | + if (\random_int(0, 100) < $chanceOfRetrieval) { |
|
| 79 | + return [ |
|
| 80 | + self::DRIVER_DATA_WRAPPER_INDEX => \bin2hex(\random_bytes($this->getConfig()->getDataLength())), |
|
| 81 | + self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
| 82 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new DateTime())->add(new DateInterval("PT{$ttl}S")), |
|
| 83 | + ]; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string $key |
|
| 91 | + * @param string $encodedKey |
|
| 92 | + * @return bool |
|
| 93 | + */ |
|
| 94 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
| 95 | + { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + protected function driverClear(): bool |
|
| 103 | + { |
|
| 104 | + return true; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + protected function driverConnect(): bool |
|
| 111 | + { |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -22,45 +22,45 @@ |
||
| 22 | 22 | |
| 23 | 23 | class Config extends ConfigurationOption |
| 24 | 24 | { |
| 25 | - protected int $dataLength = 16; |
|
| 26 | - protected int $chanceOfRetrieval = 50; |
|
| 25 | + protected int $dataLength = 16; |
|
| 26 | + protected int $chanceOfRetrieval = 50; |
|
| 27 | 27 | /** |
| 28 | - * @return int |
|
| 29 | - */ |
|
| 30 | - public function getDataLength(): int |
|
| 31 | - { |
|
| 32 | - return $this->dataLength; |
|
| 33 | - } |
|
| 28 | + * @return int |
|
| 29 | + */ |
|
| 30 | + public function getDataLength(): int |
|
| 31 | + { |
|
| 32 | + return $this->dataLength; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param int $dataLength |
|
| 37 | - * @return Config |
|
| 38 | - * @throws PhpfastcacheLogicException |
|
| 39 | - */ |
|
| 40 | - public function setDataLength(int $dataLength): Config |
|
| 41 | - { |
|
| 42 | - return $this->setProperty('dataLength', $dataLength); |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * @param int $dataLength |
|
| 37 | + * @return Config |
|
| 38 | + * @throws PhpfastcacheLogicException |
|
| 39 | + */ |
|
| 40 | + public function setDataLength(int $dataLength): Config |
|
| 41 | + { |
|
| 42 | + return $this->setProperty('dataLength', $dataLength); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return int |
|
| 47 | - */ |
|
| 48 | - public function getChanceOfRetrieval(): int |
|
| 49 | - { |
|
| 50 | - return $this->chanceOfRetrieval; |
|
| 51 | - } |
|
| 45 | + /** |
|
| 46 | + * @return int |
|
| 47 | + */ |
|
| 48 | + public function getChanceOfRetrieval(): int |
|
| 49 | + { |
|
| 50 | + return $this->chanceOfRetrieval; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param int $chanceOfRetrieval |
|
| 55 | - * @return Config |
|
| 56 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 57 | - * @throws PhpfastcacheLogicException |
|
| 58 | - */ |
|
| 59 | - public function setChanceOfRetrieval(int $chanceOfRetrieval): Config |
|
| 60 | - { |
|
| 61 | - if ($chanceOfRetrieval < 0 || $chanceOfRetrieval > 100) { |
|
| 62 | - throw new PhpfastcacheInvalidArgumentException('Chance of retrieval must be between 0 and 100'); |
|
| 63 | - } |
|
| 64 | - return $this->setProperty('chanceOfRetrieval', $chanceOfRetrieval); |
|
| 65 | - } |
|
| 53 | + /** |
|
| 54 | + * @param int $chanceOfRetrieval |
|
| 55 | + * @return Config |
|
| 56 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 57 | + * @throws PhpfastcacheLogicException |
|
| 58 | + */ |
|
| 59 | + public function setChanceOfRetrieval(int $chanceOfRetrieval): Config |
|
| 60 | + { |
|
| 61 | + if ($chanceOfRetrieval < 0 || $chanceOfRetrieval > 100) { |
|
| 62 | + throw new PhpfastcacheInvalidArgumentException('Chance of retrieval must be between 0 and 100'); |
|
| 63 | + } |
|
| 64 | + return $this->setProperty('chanceOfRetrieval', $chanceOfRetrieval); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -35,307 +35,307 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class Driver implements AggregatablePoolInterface |
| 37 | 37 | { |
| 38 | - use IOHelperTrait; |
|
| 39 | - |
|
| 40 | - /** @var array<PDO> */ |
|
| 41 | - protected array $dbInstances = []; |
|
| 42 | - protected const INDEXING_FILE = 'indexing'; |
|
| 43 | - |
|
| 44 | - protected int $maxSize = 10; |
|
| 45 | - |
|
| 46 | - protected int $currentDB = 1; |
|
| 47 | - |
|
| 48 | - protected string $sqliteDir = ''; |
|
| 49 | - |
|
| 50 | - protected ?PDO $indexing; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return bool |
|
| 54 | - * @throws PhpfastcacheCoreException |
|
| 55 | - */ |
|
| 56 | - public function driverCheck(): bool |
|
| 57 | - { |
|
| 58 | - return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return string |
|
| 63 | - * @throws PhpfastcacheCoreException |
|
| 64 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 65 | - */ |
|
| 66 | - public function getSqliteDir(): string |
|
| 67 | - { |
|
| 68 | - return $this->sqliteDir ?: $this->getPath(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function __sleep(): array |
|
| 75 | - { |
|
| 76 | - return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return bool |
|
| 81 | - * @throws PhpfastcacheIOException |
|
| 82 | - */ |
|
| 83 | - protected function driverConnect(): bool |
|
| 84 | - { |
|
| 85 | - if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)) { |
|
| 86 | - throw new PhpfastcacheIOException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $this->sqliteDir = $this->getPath(); |
|
| 90 | - |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param ExtendedCacheItemInterface $item |
|
| 96 | - * @return ?array<string, mixed> |
|
| 97 | - */ |
|
| 98 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 99 | - { |
|
| 100 | - try { |
|
| 101 | - $stm = $this->getDb($item->getEncodedKey()) |
|
| 102 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 103 | - $stm->execute( |
|
| 104 | - [ |
|
| 105 | - ':keyword' => $item->getEncodedKey(), |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 109 | - } catch (PDOException $e) { |
|
| 110 | - try { |
|
| 111 | - $stm = $this->getDb($item->getEncodedKey(), true) |
|
| 112 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 113 | - $stm->execute( |
|
| 114 | - [ |
|
| 115 | - ':keyword' => $item->getEncodedKey(), |
|
| 116 | - ] |
|
| 117 | - ); |
|
| 118 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 119 | - } catch (PDOException $e) { |
|
| 120 | - return null; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (isset($row['object'])) { |
|
| 125 | - return $this->decode($row['object']); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return null; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @param string $keyword |
|
| 133 | - * @param bool $reset |
|
| 134 | - * @return PDO |
|
| 135 | - */ |
|
| 136 | - public function getDb(string $keyword, bool $reset = false): PDO |
|
| 137 | - { |
|
| 138 | - /** |
|
| 139 | - * Default is phpfastcache |
|
| 140 | - */ |
|
| 141 | - $instant = $this->getDbIndex($keyword); |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * init instant |
|
| 145 | - */ |
|
| 146 | - if (!isset($this->dbInstances[$instant])) { |
|
| 147 | - // check DB Files ready or not |
|
| 148 | - $tableCreated = false; |
|
| 149 | - if ($reset || !file_exists($this->sqliteDir . '/db' . $instant)) { |
|
| 150 | - $tableCreated = true; |
|
| 151 | - } |
|
| 152 | - $pdo = new PDO('sqlite:' . $this->sqliteDir . '/db' . $instant); |
|
| 153 | - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 154 | - |
|
| 155 | - if ($tableCreated) { |
|
| 156 | - $this->initDB($pdo); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $this->dbInstances[$instant] = $pdo; |
|
| 160 | - unset($pdo); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $this->dbInstances[$instant]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Return Database of Keyword |
|
| 168 | - * @param string $keyword |
|
| 169 | - * @return int |
|
| 170 | - */ |
|
| 171 | - public function getDbIndex(string $keyword) |
|
| 172 | - { |
|
| 173 | - if (!isset($this->indexing)) { |
|
| 174 | - $tableCreated = false; |
|
| 175 | - if (!file_exists($this->sqliteDir . '/indexing')) { |
|
| 176 | - $tableCreated = true; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $pdo = new PDO("sqlite:" . $this->sqliteDir . '/' . self::INDEXING_FILE); |
|
| 180 | - $pdo->setAttribute( |
|
| 181 | - PDO::ATTR_ERRMODE, |
|
| 182 | - PDO::ERRMODE_EXCEPTION |
|
| 183 | - ); |
|
| 184 | - |
|
| 185 | - if ($tableCreated) { |
|
| 186 | - $this->initIndexing($pdo); |
|
| 187 | - } |
|
| 188 | - $this->indexing = $pdo; |
|
| 189 | - unset($pdo); |
|
| 190 | - |
|
| 191 | - $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); |
|
| 192 | - $stm->execute(); |
|
| 193 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 194 | - if (!isset($row['db'])) { |
|
| 195 | - $db = 1; |
|
| 196 | - } elseif ($row['db'] <= 1) { |
|
| 197 | - $db = 1; |
|
| 198 | - } else { |
|
| 199 | - $db = $row['db']; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // check file size |
|
| 203 | - |
|
| 204 | - $size = file_exists($this->sqliteDir . '/db' . $db) ? filesize($this->sqliteDir . '/db' . $db) : 1; |
|
| 205 | - $size = round($size / 1024 / 1024, 1); |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - if ($size > $this->maxSize) { |
|
| 209 | - $db++; |
|
| 210 | - } |
|
| 211 | - $this->currentDB = $db; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // look for keyword |
|
| 215 | - $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 216 | - $stm->execute( |
|
| 217 | - [ |
|
| 218 | - ':keyword' => $keyword, |
|
| 219 | - ] |
|
| 220 | - ); |
|
| 221 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 222 | - if (isset($row['db']) && $row['db'] != '') { |
|
| 223 | - $db = $row['db']; |
|
| 224 | - } else { |
|
| 225 | - /* |
|
| 38 | + use IOHelperTrait; |
|
| 39 | + |
|
| 40 | + /** @var array<PDO> */ |
|
| 41 | + protected array $dbInstances = []; |
|
| 42 | + protected const INDEXING_FILE = 'indexing'; |
|
| 43 | + |
|
| 44 | + protected int $maxSize = 10; |
|
| 45 | + |
|
| 46 | + protected int $currentDB = 1; |
|
| 47 | + |
|
| 48 | + protected string $sqliteDir = ''; |
|
| 49 | + |
|
| 50 | + protected ?PDO $indexing; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return bool |
|
| 54 | + * @throws PhpfastcacheCoreException |
|
| 55 | + */ |
|
| 56 | + public function driverCheck(): bool |
|
| 57 | + { |
|
| 58 | + return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return string |
|
| 63 | + * @throws PhpfastcacheCoreException |
|
| 64 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 65 | + */ |
|
| 66 | + public function getSqliteDir(): string |
|
| 67 | + { |
|
| 68 | + return $this->sqliteDir ?: $this->getPath(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function __sleep(): array |
|
| 75 | + { |
|
| 76 | + return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return bool |
|
| 81 | + * @throws PhpfastcacheIOException |
|
| 82 | + */ |
|
| 83 | + protected function driverConnect(): bool |
|
| 84 | + { |
|
| 85 | + if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)) { |
|
| 86 | + throw new PhpfastcacheIOException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $this->sqliteDir = $this->getPath(); |
|
| 90 | + |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param ExtendedCacheItemInterface $item |
|
| 96 | + * @return ?array<string, mixed> |
|
| 97 | + */ |
|
| 98 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 99 | + { |
|
| 100 | + try { |
|
| 101 | + $stm = $this->getDb($item->getEncodedKey()) |
|
| 102 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 103 | + $stm->execute( |
|
| 104 | + [ |
|
| 105 | + ':keyword' => $item->getEncodedKey(), |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 109 | + } catch (PDOException $e) { |
|
| 110 | + try { |
|
| 111 | + $stm = $this->getDb($item->getEncodedKey(), true) |
|
| 112 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 113 | + $stm->execute( |
|
| 114 | + [ |
|
| 115 | + ':keyword' => $item->getEncodedKey(), |
|
| 116 | + ] |
|
| 117 | + ); |
|
| 118 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 119 | + } catch (PDOException $e) { |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (isset($row['object'])) { |
|
| 125 | + return $this->decode($row['object']); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return null; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @param string $keyword |
|
| 133 | + * @param bool $reset |
|
| 134 | + * @return PDO |
|
| 135 | + */ |
|
| 136 | + public function getDb(string $keyword, bool $reset = false): PDO |
|
| 137 | + { |
|
| 138 | + /** |
|
| 139 | + * Default is phpfastcache |
|
| 140 | + */ |
|
| 141 | + $instant = $this->getDbIndex($keyword); |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * init instant |
|
| 145 | + */ |
|
| 146 | + if (!isset($this->dbInstances[$instant])) { |
|
| 147 | + // check DB Files ready or not |
|
| 148 | + $tableCreated = false; |
|
| 149 | + if ($reset || !file_exists($this->sqliteDir . '/db' . $instant)) { |
|
| 150 | + $tableCreated = true; |
|
| 151 | + } |
|
| 152 | + $pdo = new PDO('sqlite:' . $this->sqliteDir . '/db' . $instant); |
|
| 153 | + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 154 | + |
|
| 155 | + if ($tableCreated) { |
|
| 156 | + $this->initDB($pdo); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $this->dbInstances[$instant] = $pdo; |
|
| 160 | + unset($pdo); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return $this->dbInstances[$instant]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Return Database of Keyword |
|
| 168 | + * @param string $keyword |
|
| 169 | + * @return int |
|
| 170 | + */ |
|
| 171 | + public function getDbIndex(string $keyword) |
|
| 172 | + { |
|
| 173 | + if (!isset($this->indexing)) { |
|
| 174 | + $tableCreated = false; |
|
| 175 | + if (!file_exists($this->sqliteDir . '/indexing')) { |
|
| 176 | + $tableCreated = true; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $pdo = new PDO("sqlite:" . $this->sqliteDir . '/' . self::INDEXING_FILE); |
|
| 180 | + $pdo->setAttribute( |
|
| 181 | + PDO::ATTR_ERRMODE, |
|
| 182 | + PDO::ERRMODE_EXCEPTION |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + if ($tableCreated) { |
|
| 186 | + $this->initIndexing($pdo); |
|
| 187 | + } |
|
| 188 | + $this->indexing = $pdo; |
|
| 189 | + unset($pdo); |
|
| 190 | + |
|
| 191 | + $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); |
|
| 192 | + $stm->execute(); |
|
| 193 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 194 | + if (!isset($row['db'])) { |
|
| 195 | + $db = 1; |
|
| 196 | + } elseif ($row['db'] <= 1) { |
|
| 197 | + $db = 1; |
|
| 198 | + } else { |
|
| 199 | + $db = $row['db']; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // check file size |
|
| 203 | + |
|
| 204 | + $size = file_exists($this->sqliteDir . '/db' . $db) ? filesize($this->sqliteDir . '/db' . $db) : 1; |
|
| 205 | + $size = round($size / 1024 / 1024, 1); |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + if ($size > $this->maxSize) { |
|
| 209 | + $db++; |
|
| 210 | + } |
|
| 211 | + $this->currentDB = $db; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // look for keyword |
|
| 215 | + $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 216 | + $stm->execute( |
|
| 217 | + [ |
|
| 218 | + ':keyword' => $keyword, |
|
| 219 | + ] |
|
| 220 | + ); |
|
| 221 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
| 222 | + if (isset($row['db']) && $row['db'] != '') { |
|
| 223 | + $db = $row['db']; |
|
| 224 | + } else { |
|
| 225 | + /* |
|
| 226 | 226 | * Insert new to Indexing |
| 227 | 227 | */ |
| 228 | - $db = $this->currentDB; |
|
| 229 | - $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
|
| 230 | - $stm->execute( |
|
| 231 | - [ |
|
| 232 | - ':keyword' => $keyword, |
|
| 233 | - ':db' => $db, |
|
| 234 | - ] |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return $db; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * INIT Indexing DB |
|
| 243 | - * @param PDO $db |
|
| 244 | - */ |
|
| 245 | - public function initIndexing(PDO $db): void |
|
| 246 | - { |
|
| 247 | - // delete everything before reset indexing |
|
| 248 | - $dir = opendir($this->sqliteDir); |
|
| 249 | - while ($file = readdir($dir)) { |
|
| 250 | - if ($file !== '.' && $file !== '..' && $file !== 'indexing' && $file !== 'dbfastcache') { |
|
| 251 | - unlink($this->sqliteDir . '/' . $file); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $db->exec('DROP TABLE if exists "balancing"'); |
|
| 256 | - $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); |
|
| 257 | - $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); |
|
| 258 | - $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * INIT NEW DB |
|
| 263 | - * @param PDO $db |
|
| 264 | - */ |
|
| 265 | - protected function initDB(PDO $db): void |
|
| 266 | - { |
|
| 267 | - $db->exec('drop table if exists "caching"'); |
|
| 268 | - $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); |
|
| 269 | - $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); |
|
| 270 | - $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); |
|
| 271 | - $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @param ExtendedCacheItemInterface $item |
|
| 276 | - * @return mixed |
|
| 277 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 278 | - * @throws PhpfastcacheLogicException |
|
| 279 | - */ |
|
| 280 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 281 | - { |
|
| 282 | - |
|
| 283 | - try { |
|
| 284 | - $stm = $this->getDb($item->getEncodedKey()) |
|
| 285 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 286 | - $stm->execute( |
|
| 287 | - [ |
|
| 288 | - ':keyword' => $item->getEncodedKey(), |
|
| 289 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 290 | - ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 291 | - ] |
|
| 292 | - ); |
|
| 293 | - |
|
| 294 | - return true; |
|
| 295 | - } catch (PDOException $e) { |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $key |
|
| 302 | - * @param string $encodedKey |
|
| 303 | - * @return bool |
|
| 304 | - */ |
|
| 305 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
| 306 | - { |
|
| 307 | - try { |
|
| 308 | - $stm = $this->getDb($encodedKey) |
|
| 309 | - ->prepare("DELETE FROM `caching` WHERE (`exp` <= :exp) OR (`keyword`=:keyword) "); |
|
| 310 | - |
|
| 311 | - return $stm->execute( |
|
| 312 | - [ |
|
| 313 | - ':keyword' => $encodedKey, |
|
| 314 | - ':exp' => time(), |
|
| 315 | - ] |
|
| 316 | - ); |
|
| 317 | - } catch (PDOException $e) { |
|
| 318 | - return false; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @return bool |
|
| 324 | - * @throws PhpfastcacheCoreException |
|
| 325 | - */ |
|
| 326 | - protected function driverClear(): bool |
|
| 327 | - { |
|
| 328 | - $this->dbInstances = []; |
|
| 329 | - $this->indexing = null; |
|
| 330 | - |
|
| 331 | - // delete everything before reset indexing |
|
| 332 | - $dir = opendir($this->getSqliteDir()); |
|
| 333 | - while ($file = readdir($dir)) { |
|
| 334 | - if ($file !== '.' && $file !== '..') { |
|
| 335 | - unlink($this->getSqliteDir() . '/' . $file); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return true; |
|
| 340 | - } |
|
| 228 | + $db = $this->currentDB; |
|
| 229 | + $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
|
| 230 | + $stm->execute( |
|
| 231 | + [ |
|
| 232 | + ':keyword' => $keyword, |
|
| 233 | + ':db' => $db, |
|
| 234 | + ] |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return $db; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * INIT Indexing DB |
|
| 243 | + * @param PDO $db |
|
| 244 | + */ |
|
| 245 | + public function initIndexing(PDO $db): void |
|
| 246 | + { |
|
| 247 | + // delete everything before reset indexing |
|
| 248 | + $dir = opendir($this->sqliteDir); |
|
| 249 | + while ($file = readdir($dir)) { |
|
| 250 | + if ($file !== '.' && $file !== '..' && $file !== 'indexing' && $file !== 'dbfastcache') { |
|
| 251 | + unlink($this->sqliteDir . '/' . $file); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $db->exec('DROP TABLE if exists "balancing"'); |
|
| 256 | + $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); |
|
| 257 | + $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); |
|
| 258 | + $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * INIT NEW DB |
|
| 263 | + * @param PDO $db |
|
| 264 | + */ |
|
| 265 | + protected function initDB(PDO $db): void |
|
| 266 | + { |
|
| 267 | + $db->exec('drop table if exists "caching"'); |
|
| 268 | + $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); |
|
| 269 | + $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); |
|
| 270 | + $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); |
|
| 271 | + $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @param ExtendedCacheItemInterface $item |
|
| 276 | + * @return mixed |
|
| 277 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 278 | + * @throws PhpfastcacheLogicException |
|
| 279 | + */ |
|
| 280 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 281 | + { |
|
| 282 | + |
|
| 283 | + try { |
|
| 284 | + $stm = $this->getDb($item->getEncodedKey()) |
|
| 285 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 286 | + $stm->execute( |
|
| 287 | + [ |
|
| 288 | + ':keyword' => $item->getEncodedKey(), |
|
| 289 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 290 | + ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 291 | + ] |
|
| 292 | + ); |
|
| 293 | + |
|
| 294 | + return true; |
|
| 295 | + } catch (PDOException $e) { |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $key |
|
| 302 | + * @param string $encodedKey |
|
| 303 | + * @return bool |
|
| 304 | + */ |
|
| 305 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
| 306 | + { |
|
| 307 | + try { |
|
| 308 | + $stm = $this->getDb($encodedKey) |
|
| 309 | + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :exp) OR (`keyword`=:keyword) "); |
|
| 310 | + |
|
| 311 | + return $stm->execute( |
|
| 312 | + [ |
|
| 313 | + ':keyword' => $encodedKey, |
|
| 314 | + ':exp' => time(), |
|
| 315 | + ] |
|
| 316 | + ); |
|
| 317 | + } catch (PDOException $e) { |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @return bool |
|
| 324 | + * @throws PhpfastcacheCoreException |
|
| 325 | + */ |
|
| 326 | + protected function driverClear(): bool |
|
| 327 | + { |
|
| 328 | + $this->dbInstances = []; |
|
| 329 | + $this->indexing = null; |
|
| 330 | + |
|
| 331 | + // delete everything before reset indexing |
|
| 332 | + $dir = opendir($this->getSqliteDir()); |
|
| 333 | + while ($file = readdir($dir)) { |
|
| 334 | + if ($file !== '.' && $file !== '..') { |
|
| 335 | + unlink($this->getSqliteDir() . '/' . $file); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return true; |
|
| 340 | + } |
|
| 341 | 341 | } |