Firestore/src/ValueMapper.php
public function encodeValue($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'boolean':
                return ['booleanValue' => $value];
                break;

            case 'integer':
                return ['integerValue' => $value];
                break;

            case 'double':
                return ['doubleValue' => $value];
                break;

            case 'string':
                return ['stringValue' => $value];
                break;

            case 'resource':
                return ['bytesValue' => stream_get_contents($value)];
                break;

            case 'object':
                return $this->encodeObjectValue($value);
                break;

            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return $this->encodeAssociativeArrayValue($value);
                }

                return ['arrayValue' => $this->encodeArrayValue($value)];
                break;

            case 'NULL':
                // @todo encode this in a way such that is compatible with a potential future REST transport.
                return ['nullValue' => NullValue::NULL_VALUE];
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \RuntimeException(sprintf(
                    'Invalid value type %s',
                    $type
                ));
                break;
            // @codeCoverageIgnoreEnd
        }
    }
public function encodeValue($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'boolean':
                return ['booleanValue' => $value];
                break;

            case 'integer':
                return ['integerValue' => $value];
                break;

            case 'double':
                return ['doubleValue' => $value];
                break;

            case 'string':
                return ['stringValue' => $value];
                break;

            case 'resource':
                return ['bytesValue' => stream_get_contents($value)];
                break;

            case 'object':
                return $this->encodeObjectValue($value);
                break;

            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return $this->encodeAssociativeArrayValue($value);
                }

                return ['arrayValue' => $this->encodeArrayValue($value)];
                break;

            case 'NULL':
                // @todo encode this in a way such that is compatible with a potential future REST transport.
                return ['nullValue' => NullValue::NULL_VALUE];
                break;

            // @codeCoverageIgnoreStart
            default:
                throw new \RuntimeException(sprintf(
                    'Invalid value type %s',
                    $type
                ));
                break;
            // @codeCoverageIgnoreEnd
        }
    }
public function encodeValue ( $ value ) { $ type = gettype ( $ value ) ; switch ( $ type ) { case 'boolean' : return [ 'booleanValue' => $ value ] ; break ; case 'integer' : return [ 'integerValue' => $ value ] ; break ; case 'double' : return [ 'doubleValue' => $ value ] ; break ; case 'string' : return [ 'stringValue' => $ value ] ; break ; case 'resource' : return [ 'bytesValue' => stream_get_contents ( $ value ) ] ; break ; case 'object' : return $ this -> encodeObjectValue ( $ value ) ; break ; case 'array' : if ( ! empty ( $ value ) && $ this -> isAssoc ( $ value ) ) { return $ this -> encodeAssociativeArrayValue ( $ value ) ; } return [ 'arrayValue' => $ this -> encodeArrayValue ( $ value ) ] ; break ; case 'NULL' : // @todo encode this in a way such that is compatible with a potential future REST transport. return [ 'nullValue' => NullValue :: NULL_VALUE ] ; break ; // @codeCoverageIgnoreStart default : throw new \ RuntimeException ( sprintf ( 'Invalid value type %s' , $ type ) ) ; break ; // @codeCoverageIgnoreEnd } }
Encode a Google Cloud PHP value as a Firestore value.

@param mixed $value
@return array [Value](https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1beta1#value)
@throws \RuntimeException If an unknown type is encountered.
Encode a Google Cloud PHP value as a Firestore value .