diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/cache/Adapter/ApcuAdapter.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/cache/Adapter/ApcuAdapter.php')
| -rw-r--r-- | vendor/symfony/cache/Adapter/ApcuAdapter.php | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/vendor/symfony/cache/Adapter/ApcuAdapter.php b/vendor/symfony/cache/Adapter/ApcuAdapter.php new file mode 100644 index 0000000..03b512f --- /dev/null +++ b/vendor/symfony/cache/Adapter/ApcuAdapter.php | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Cache\Adapter; | ||
| 13 | |||
| 14 | use Symfony\Component\Cache\CacheItem; | ||
| 15 | use Symfony\Component\Cache\Exception\CacheException; | ||
| 16 | use Symfony\Component\Cache\Marshaller\MarshallerInterface; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @author Nicolas Grekas <p@tchwork.com> | ||
| 20 | */ | ||
| 21 | class ApcuAdapter extends AbstractAdapter | ||
| 22 | { | ||
| 23 | /** | ||
| 24 | * @throws CacheException if APCu is not enabled | ||
| 25 | */ | ||
| 26 | public function __construct( | ||
| 27 | string $namespace = '', | ||
| 28 | int $defaultLifetime = 0, | ||
| 29 | ?string $version = null, | ||
| 30 | private ?MarshallerInterface $marshaller = null, | ||
| 31 | ) { | ||
| 32 | if (!static::isSupported()) { | ||
| 33 | throw new CacheException('APCu is not enabled.'); | ||
| 34 | } | ||
| 35 | if ('cli' === \PHP_SAPI) { | ||
| 36 | ini_set('apc.use_request_time', 0); | ||
| 37 | } | ||
| 38 | parent::__construct($namespace, $defaultLifetime); | ||
| 39 | |||
| 40 | if (null !== $version) { | ||
| 41 | CacheItem::validateKey($version); | ||
| 42 | |||
| 43 | if (!apcu_exists($version.'@'.$namespace)) { | ||
| 44 | $this->doClear($namespace); | ||
| 45 | apcu_add($version.'@'.$namespace, null); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | public static function isSupported(): bool | ||
| 51 | { | ||
| 52 | return \function_exists('apcu_fetch') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL); | ||
| 53 | } | ||
| 54 | |||
| 55 | protected function doFetch(array $ids): iterable | ||
| 56 | { | ||
| 57 | $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback'); | ||
| 58 | try { | ||
| 59 | $values = []; | ||
| 60 | foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) { | ||
| 61 | if (null !== $v || $ok) { | ||
| 62 | $values[$k] = null !== $this->marshaller ? $this->marshaller->unmarshall($v) : $v; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | return $values; | ||
| 67 | } catch (\Error $e) { | ||
| 68 | throw new \ErrorException($e->getMessage(), $e->getCode(), \E_ERROR, $e->getFile(), $e->getLine()); | ||
| 69 | } finally { | ||
| 70 | ini_set('unserialize_callback_func', $unserializeCallbackHandler); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | protected function doHave(string $id): bool | ||
| 75 | { | ||
| 76 | return apcu_exists($id); | ||
| 77 | } | ||
| 78 | |||
| 79 | protected function doClear(string $namespace): bool | ||
| 80 | { | ||
| 81 | return isset($namespace[0]) && class_exists(\APCUIterator::class, false) && ('cli' !== \PHP_SAPI || filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) | ||
| 82 | ? apcu_delete(new \APCUIterator(sprintf('/^%s/', preg_quote($namespace, '/')), \APC_ITER_KEY)) | ||
| 83 | : apcu_clear_cache(); | ||
| 84 | } | ||
| 85 | |||
| 86 | protected function doDelete(array $ids): bool | ||
| 87 | { | ||
| 88 | foreach ($ids as $id) { | ||
| 89 | apcu_delete($id); | ||
| 90 | } | ||
| 91 | |||
| 92 | return true; | ||
| 93 | } | ||
| 94 | |||
| 95 | protected function doSave(array $values, int $lifetime): array|bool | ||
| 96 | { | ||
| 97 | if (null !== $this->marshaller && (!$values = $this->marshaller->marshall($values, $failed))) { | ||
| 98 | return $failed; | ||
| 99 | } | ||
| 100 | |||
| 101 | try { | ||
| 102 | if (false === $failures = apcu_store($values, null, $lifetime)) { | ||
| 103 | $failures = $values; | ||
| 104 | } | ||
| 105 | |||
| 106 | return array_keys($failures); | ||
| 107 | } catch (\Throwable $e) { | ||
| 108 | if (1 === \count($values)) { | ||
| 109 | // Workaround https://github.com/krakjoe/apcu/issues/170 | ||
| 110 | apcu_delete(array_key_first($values)); | ||
| 111 | } | ||
| 112 | |||
| 113 | throw $e; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
