Doctrine\ODM\MongoDB\MongoDBException::invalidValueForType PHP Method

invalidValueForType() public static method

public static invalidValueForType ( string $type, string | array $expected, mixed $got ) : MongoDBException
$type string
$expected string | array
$got mixed
return MongoDBException
    public static function invalidValueForType($type, $expected, $got)
    {
        if (is_array($expected)) {
            $expected = sprintf('%s or %s', join(', ', array_slice($expected, 0, -1)), end($expected));
        }
        if (is_object($got)) {
            $gotType = get_class($got);
        } elseif (is_array($got)) {
            $gotType = 'array';
        } else {
            $gotType = 'scalar';
        }
        return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType));
    }

Usage Example

Ejemplo n.º 1
0
 public function convertToDatabaseValue($value)
 {
     if ($value !== null && !is_array($value)) {
         throw MongoDBException::invalidValueForType('Hash', array('array', 'null'), $value);
     }
     return $value !== null ? (object) $value : null;
 }
All Usage Examples Of Doctrine\ODM\MongoDB\MongoDBException::invalidValueForType