Webmozart\KeyValueStore\Api\UnsupportedValueException::forType PHP Method

forType() public static method

Creates a new exception for the given value type.
public static forType ( string $type, Webmozart\KeyValueStore\Api\KeyValueStore $store, integer $code, Exception $cause = null ) : static
$type string The name of the unsupported type.
$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.
    public static function forType($type, KeyValueStore $store, $code = 0, Exception $cause = null)
    {
        return new static(sprintf('Values of type %s are not supported by %s.', $type, get_class($store)), $code, $cause);
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function set($key, $value)
 {
     KeyUtil::validate($key);
     $serialized = $this->serialize->__invoke($value);
     try {
         $this->collection->replaceOne(array('_id' => $key), array('_id' => $key, 'value' => $serialized), array('upsert' => true));
     } catch (UnexpectedValueException $e) {
         throw UnsupportedValueException::forType('binary', $this, 0, $e);
     } catch (Exception $e) {
         throw WriteException::forException($e);
     }
 }
All Usage Examples Of Webmozart\KeyValueStore\Api\UnsupportedValueException::forType
UnsupportedValueException