forValue() public static method

Creates a new exception for the given value.
public static forValue ( string $value, Webmozart\KeyValueStore\Api\KeyValueStore $store, integer $code, Exception $cause = null ) : static
$value string The unsupported value.
$store Webmozart\KeyValueStore\Api\KeyValueStore The store that does not support the type.
$code integer The exception code.
$cause Exception The exception that caused this exception.
return static The new exception.
Esempio n. 1
0
 public function __construct(Collection $collection, $flags = 0)
 {
     $this->collection = $collection;
     if ($flags & self::NO_SERIALIZE) {
         if ($flags & self::SUPPORT_BINARY) {
             $this->serialize = function ($unserialized) {
                 if (!is_string($unserialized)) {
                     throw UnsupportedValueException::forValue($unserialized, $this);
                 }
                 return new Binary($unserialized, Binary::TYPE_GENERIC);
             };
             $this->unserialize = function (Binary $serialized) {
                 return $serialized->getData();
             };
         } else {
             $this->serialize = function ($unserialized) {
                 if (!is_scalar($unserialized) && !is_array($unserialized) && null !== $unserialized) {
                     throw UnsupportedValueException::forValue($unserialized, $this);
                 }
                 return $unserialized;
             };
             $this->unserialize = function ($serialized) {
                 return $serialized;
             };
         }
     } else {
         if ($flags & self::SUPPORT_BINARY) {
             $this->serialize = function ($unserialized) {
                 return new Binary(Serializer::serialize($unserialized), Binary::TYPE_GENERIC);
             };
             $this->unserialize = function (Binary $serialized) {
                 return Serializer::unserialize($serialized->getData());
             };
         } else {
             $this->serialize = function ($unserialized) {
                 return Serializer::serialize($unserialized);
             };
             $this->unserialize = function ($serialized) {
                 return Serializer::unserialize($serialized);
             };
         }
     }
 }