for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Cache package.
*
* Copyright (c) Daniel González
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @author Daniel González <[email protected]>
* @author Arnold Daniels <[email protected]>
*/
declare(strict_types=1);
namespace Desarrolla2\Cache\Packer;
use Desarrolla2\Cache\Packer\PackerInterface;
use Desarrolla2\Cache\Exception\InvalidArgumentException;
/**
* Pack value through serialization
class SerializePacker implements PackerInterface
{
* @var array
protected $options;
* SerializePacker constructor
* @param array $options Any options to be provided to unserialize()
public function __construct(array $options = ['allowed_classes' => true])
$this->options = $options;
}
* Get cache type (might be used as file extension)
* @return string
public function getType()
return 'php.cache';
* Pack the value
* @param mixed $value
public function pack($value)
return serialize($value);
* Unpack the value
* @param string $packed
* @throws \UnexpectedValueException if he value can't be unpacked
public function unpack($packed)
if (!is_string($packed)) {
is_string($packed)
true
throw new InvalidArgumentException("packed value should be a string");
return unserialize($packed, $this->options);