Spanner/src/ValueMapper.php
private function arrayParam($value, ArrayType $arrayType, $allowMixedArrayType = false)
    {
        if (!is_array($value) && $value !== null) {
            throw new \InvalidArgumentException('Array value must be an array or null.');
        }

        $inferredTypes = [];
        $res = null;
        if ($value !== null) {
            $res = [];
            foreach ($value as $element) {
                $type = $this->paramType(
                    $element,
                    $arrayType->type() === Database::TYPE_STRUCT ? $arrayType->type() : null,
                    $arrayType->structType()
                );

                $res[] = $type[0];
                if (isset($type[1]['code'])) {
                    $inferredTypes[] = $type[1]['code'];
                }
            }
        }

        if (!$allowMixedArrayType && count(array_unique($inferredTypes)) > 1) {
            throw new \InvalidArgumentException('Array values may not be of mixed type');
        }

        $nested = $arrayType->structType();
        $arrayType = $arrayType->type();

        if (!empty($value) && $arrayType && $arrayType !== $inferredTypes[0]) {
            throw new \InvalidArgumentException('Array data does not match given array parameter type.');
        }

        $typeCode = $arrayType === null && $inferredTypes
            ? $inferredTypes[0]
            : $arrayType;

        if ($nested) {
            $nestedDefType = $this->resolveTypeDefinition($nested);
            $nestedDef = $this->paramType(null, $nestedDefType[0], $nestedDefType[1]);

            $typeObject = $nestedDef[1];
        } else {
            $typeObject = $this->typeObject($typeCode);
        }

        $type = $this->typeObject(
            self::TYPE_ARRAY,
            $typeObject,
            'arrayElementType'
        );

        return [$res, $type];
    }
private function arrayParam($value, ArrayType $arrayType, $allowMixedArrayType = false)
    {
        if (!is_array($value) && $value !== null) {
            throw new \InvalidArgumentException('Array value must be an array or null.');
        }

        $inferredTypes = [];
        $res = null;
        if ($value !== null) {
            $res = [];
            foreach ($value as $element) {
                $type = $this->paramType(
                    $element,
                    $arrayType->type() === Database::TYPE_STRUCT ? $arrayType->type() : null,
                    $arrayType->structType()
                );

                $res[] = $type[0];
                if (isset($type[1]['code'])) {
                    $inferredTypes[] = $type[1]['code'];
                }
            }
        }

        if (!$allowMixedArrayType && count(array_unique($inferredTypes)) > 1) {
            throw new \InvalidArgumentException('Array values may not be of mixed type');
        }

        $nested = $arrayType->structType();
        $arrayType = $arrayType->type();

        if (!empty($value) && $arrayType && $arrayType !== $inferredTypes[0]) {
            throw new \InvalidArgumentException('Array data does not match given array parameter type.');
        }

        $typeCode = $arrayType === null && $inferredTypes
            ? $inferredTypes[0]
            : $arrayType;

        if ($nested) {
            $nestedDefType = $this->resolveTypeDefinition($nested);
            $nestedDef = $this->paramType(null, $nestedDefType[0], $nestedDefType[1]);

            $typeObject = $nestedDef[1];
        } else {
            $typeObject = $this->typeObject($typeCode);
        }

        $type = $this->typeObject(
            self::TYPE_ARRAY,
            $typeObject,
            'arrayElementType'
        );

        return [$res, $type];
    }
private function arrayParam ( $ value , ArrayType $ arrayType , $ allowMixedArrayType = false ) { if ( ! is_array ( $ value ) && $ value !== null ) { throw new \ InvalidArgumentException ( 'Array value must be an array or null.' ) ; } $ inferredTypes = [ ] ; $ res = null ; if ( $ value !== null ) { $ res = [ ] ; foreach ( $ value as $ element ) { $ type = $ this -> paramType ( $ element , $ arrayType -> type ( ) === Database :: TYPE_STRUCT ? $ arrayType -> type ( ) : null , $ arrayType -> structType ( ) ) ; $ res [ ] = $ type [ 0 ] ; if ( isset ( $ type [ 1 ] [ 'code' ] ) ) { $ inferredTypes [ ] = $ type [ 1 ] [ 'code' ] ; } } } if ( ! $ allowMixedArrayType && count ( array_unique ( $ inferredTypes ) ) > 1 ) { throw new \ InvalidArgumentException ( 'Array values may not be of mixed type' ) ; } $ nested = $ arrayType -> structType ( ) ; $ arrayType = $ arrayType -> type ( ) ; if ( ! empty ( $ value ) && $ arrayType && $ arrayType !== $ inferredTypes [ 0 ] ) { throw new \ InvalidArgumentException ( 'Array data does not match given array parameter type.' ) ; } $ typeCode = $ arrayType === null && $ inferredTypes ? $ inferredTypes [ 0 ] : $ arrayType ; if ( $ nested ) { $ nestedDefType = $ this -> resolveTypeDefinition ( $ nested ) ; $ nestedDef = $ this -> paramType ( null , $ nestedDefType [ 0 ] , $ nestedDefType [ 1 ] ) ; $ typeObject = $ nestedDef [ 1 ] ; } else { $ typeObject = $ this -> typeObject ( $ typeCode ) ; } $ type = $ this -> typeObject ( self :: TYPE_ARRAY , $ typeObject , 'arrayElementType' ) ; return [ $ res , $ type ] ; }
Create value and paramater type declarations for array SQL parameters.

@param array $value The array values.
@param ArrayType $arrayType The array type declaration.
@param bool $allowMixedArrayType [optional] If true, array values may be of mixed type.
This is useful when reading against complex keys containing multiple
elements of differing types.
@return [array, array] An array containing the value and type.
Create value and paramater type declarations for array SQL parameters .