├── README.md ├── composer.json ├── LICENSE ├── Apcu.php ├── bootstrap80.php └── bootstrap.php /README.md: -------------------------------------------------------------------------------- 1 | Symfony Polyfill / APCu 2 | ======================== 3 | 4 | This component provides `apcu_*` functions and the `APCuIterator` class to users of the legacy APC extension. 5 | 6 | More information can be found in the 7 | [main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md). 8 | 9 | License 10 | ======= 11 | 12 | This library is released under the [MIT license](LICENSE). 13 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "symfony/polyfill-apcu", 3 | "type": "library", 4 | "description": "Symfony polyfill backporting apcu_* functions to lower PHP versions", 5 | "keywords": ["polyfill", "shim", "compatibility", "portable", "apcu"], 6 | "homepage": "https://symfony.com", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Nicolas Grekas", 11 | "email": "p@tchwork.com" 12 | }, 13 | { 14 | "name": "Symfony Community", 15 | "homepage": "https://symfony.com/contributors" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=7.2" 20 | }, 21 | "autoload": { 22 | "psr-4": { "Symfony\\Polyfill\\Apcu\\": "" }, 23 | "files": [ "bootstrap.php" ] 24 | }, 25 | "minimum-stability": "dev", 26 | "extra": { 27 | "thanks": { 28 | "name": "symfony/polyfill", 29 | "url": "https://github.com/symfony/polyfill" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-present Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Apcu.php: -------------------------------------------------------------------------------- 1 | 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\Polyfill\Apcu; 13 | 14 | /** 15 | * Apcu for Zend Server Data Cache. 16 | * 17 | * @author Kate Gray 18 | * @author Nicolas Grekas 19 | * 20 | * @internal 21 | */ 22 | final class Apcu 23 | { 24 | public static function apcu_add($key, $var = null, $ttl = 0) 25 | { 26 | if (!\is_array($key)) { 27 | return apc_add($key, $var, $ttl); 28 | } 29 | 30 | $errors = []; 31 | foreach ($key as $k => $v) { 32 | if (!apc_add($k, $v, $ttl)) { 33 | $errors[$k] = -1; 34 | } 35 | } 36 | 37 | return $errors; 38 | } 39 | 40 | public static function apcu_store($key, $var = null, $ttl = 0) 41 | { 42 | if (!\is_array($key)) { 43 | return apc_store($key, $var, $ttl); 44 | } 45 | 46 | $errors = []; 47 | foreach ($key as $k => $v) { 48 | if (!apc_store($k, $v, $ttl)) { 49 | $errors[$k] = -1; 50 | } 51 | } 52 | 53 | return $errors; 54 | } 55 | 56 | public static function apcu_exists($keys) 57 | { 58 | if (!\is_array($keys)) { 59 | return apc_exists($keys); 60 | } 61 | 62 | $existing = []; 63 | foreach ($keys as $k) { 64 | if (apc_exists($k)) { 65 | $existing[$k] = true; 66 | } 67 | } 68 | 69 | return $existing; 70 | } 71 | 72 | public static function apcu_fetch($key, &$success = null) 73 | { 74 | if (!\is_array($key)) { 75 | return apc_fetch($key, $success); 76 | } 77 | 78 | $succeeded = true; 79 | $values = []; 80 | foreach ($key as $k) { 81 | $v = apc_fetch($k, $success); 82 | if ($success) { 83 | $values[$k] = $v; 84 | } else { 85 | $succeeded = false; 86 | } 87 | } 88 | $success = $succeeded; 89 | 90 | return $values; 91 | } 92 | 93 | public static function apcu_delete($key) 94 | { 95 | if (!\is_array($key)) { 96 | return apc_delete($key); 97 | } 98 | 99 | $success = true; 100 | foreach ($key as $k) { 101 | $success = apc_delete($k) && $success; 102 | } 103 | 104 | return $success; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /bootstrap80.php: -------------------------------------------------------------------------------- 1 | 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 | use Symfony\Polyfill\Apcu as p; 13 | 14 | if (extension_loaded('Zend Data Cache')) { 15 | if (!function_exists('apcu_add')) { 16 | function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_add($key, $value, (int) $ttl); } 17 | } 18 | if (!function_exists('apcu_delete')) { 19 | function apcu_delete($key): array|bool { return p\Apcu::apcu_delete($key); } 20 | } 21 | if (!function_exists('apcu_exists')) { 22 | function apcu_exists($key): array|bool { return p\Apcu::apcu_exists($key); } 23 | } 24 | if (!function_exists('apcu_fetch')) { 25 | function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); } 26 | } 27 | if (!function_exists('apcu_store')) { 28 | function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_store($key, $value, (int) $ttl); } 29 | } 30 | } else { 31 | if (!function_exists('apcu_add')) { 32 | function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return apc_add($key, $value, (int) $ttl); } 33 | } 34 | if (!function_exists('apcu_delete')) { 35 | function apcu_delete($key): array|bool { return apc_delete($key); } 36 | } 37 | if (!function_exists('apcu_exists')) { 38 | function apcu_exists($key): array|bool { return apc_exists($key); } 39 | } 40 | if (!function_exists('apcu_fetch')) { 41 | function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } 42 | } 43 | if (!function_exists('apcu_store')) { 44 | function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return apc_store($key, $value, (int) $ttl); } 45 | } 46 | } 47 | 48 | if (!function_exists('apcu_cache_info')) { 49 | function apcu_cache_info($limited = false) { return apc_cache_info('user', $limited); } 50 | } 51 | if (!function_exists('apcu_cas')) { 52 | function apcu_cas($key, $old, $new) { return apc_cas($key, $old, $new); } 53 | } 54 | if (!function_exists('apcu_clear_cache')) { 55 | function apcu_clear_cache() { return apc_clear_cache('user'); } 56 | } 57 | if (!function_exists('apcu_dec')) { 58 | function apcu_dec($key, $step = 1, &$success = false) { return apc_dec($key, $step, $success); } 59 | } 60 | if (!function_exists('apcu_inc')) { 61 | function apcu_inc($key, $step = 1, &$success = false) { return apc_inc($key, $step, $success); } 62 | } 63 | if (!function_exists('apcu_sma_info')) { 64 | function apcu_sma_info($limited = false) { return apc_sma_info($limited); } 65 | } 66 | 67 | if (!class_exists('APCuIterator', false) && class_exists('APCIterator', false)) { 68 | class APCuIterator extends APCIterator 69 | { 70 | public function __construct($search = null, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) 71 | { 72 | parent::__construct('user', $search, $format, $chunk_size, $list); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | 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 | use Symfony\Polyfill\Apcu as p; 13 | 14 | if (!extension_loaded('apc') && !extension_loaded('apcu')) { 15 | return; 16 | } 17 | 18 | if (\PHP_VERSION_ID >= 80000) { 19 | return require __DIR__.'/bootstrap80.php'; 20 | } 21 | 22 | if (extension_loaded('Zend Data Cache')) { 23 | if (!function_exists('apcu_add')) { 24 | function apcu_add($key, $value = null, $ttl = 0) { return p\Apcu::apcu_add($key, $value, $ttl); } 25 | } 26 | if (!function_exists('apcu_delete')) { 27 | function apcu_delete($key) { return p\Apcu::apcu_delete($key); } 28 | } 29 | if (!function_exists('apcu_exists')) { 30 | function apcu_exists($key) { return p\Apcu::apcu_exists($key); } 31 | } 32 | if (!function_exists('apcu_fetch')) { 33 | function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); } 34 | } 35 | if (!function_exists('apcu_store')) { 36 | function apcu_store($key, $value = null, $ttl = 0) { return p\Apcu::apcu_store($key, $value, $ttl); } 37 | } 38 | } else { 39 | if (!function_exists('apcu_add')) { 40 | function apcu_add($key, $value = null, $ttl = 0) { return apc_add($key, $value, $ttl); } 41 | } 42 | if (!function_exists('apcu_delete')) { 43 | function apcu_delete($key) { return apc_delete($key); } 44 | } 45 | if (!function_exists('apcu_exists')) { 46 | function apcu_exists($key) { return apc_exists($key); } 47 | } 48 | if (!function_exists('apcu_fetch')) { 49 | function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } 50 | } 51 | if (!function_exists('apcu_store')) { 52 | function apcu_store($key, $value = null, $ttl = 0) { return apc_store($key, $value, $ttl); } 53 | } 54 | } 55 | 56 | if (!function_exists('apcu_cache_info')) { 57 | function apcu_cache_info($limited = false) { return apc_cache_info('user', $limited); } 58 | } 59 | if (!function_exists('apcu_cas')) { 60 | function apcu_cas($key, $old, $new) { return apc_cas($key, $old, $new); } 61 | } 62 | if (!function_exists('apcu_clear_cache')) { 63 | function apcu_clear_cache() { return apc_clear_cache('user'); } 64 | } 65 | if (!function_exists('apcu_dec')) { 66 | function apcu_dec($key, $step = 1, &$success = false) { return apc_dec($key, $step, $success); } 67 | } 68 | if (!function_exists('apcu_inc')) { 69 | function apcu_inc($key, $step = 1, &$success = false) { return apc_inc($key, $step, $success); } 70 | } 71 | if (!function_exists('apcu_sma_info')) { 72 | function apcu_sma_info($limited = false) { return apc_sma_info($limited); } 73 | } 74 | 75 | if (!class_exists('APCuIterator', false) && class_exists('APCIterator', false)) { 76 | class APCuIterator extends APCIterator 77 | { 78 | public function __construct($search = null, $format = \APC_ITER_ALL, $chunk_size = 100, $list = \APC_LIST_ACTIVE) 79 | { 80 | parent::__construct('user', $search, $format, $chunk_size, $list); 81 | } 82 | } 83 | } 84 | --------------------------------------------------------------------------------