3 * @see https://github.com/zendframework/zend-cache for the canonical source repository
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
8 namespace Zend\Cache\Psr
;
10 use Zend\Cache\Storage\StorageInterface
;
13 * Provides common functionality surrounding value de/serialization as required
14 * by both PSR-6 and PSR-16
16 trait SerializationTrait
19 * Determine if the given storage adapter requires serialization.
21 * @param StorageInterface $storage
24 private function isSerializationRequired(StorageInterface
$storage)
26 $capabilities = $storage->getCapabilities();
27 $requiredTypes = ['string', 'integer', 'double', 'boolean', 'NULL', 'array', 'object'];
28 $types = $capabilities->getSupportedDatatypes();
30 foreach ($requiredTypes as $type) {
31 // 'object' => 'object' is OK
32 // 'integer' => 'string' is not (redis)
33 // 'integer' => 'integer' is not (memcache)
34 if (! (isset($types[$type]) && in_array($types[$type], [true, 'array', 'object'], true))) {