Spanner/src/StructType.php
public function add($name, $type)
    {
        $invalidIntTypes = [
            Database::TYPE_STRUCT,
            Database::TYPE_ARRAY
        ];

        if (is_int($type) && in_array($type, $invalidIntTypes)) {
            throw new \InvalidArgumentException(
                '`Database::TYPE_ARRAY` and `Database::TYPE_STRUCT` are not valid as struct types. ' .
                'Instead provide `Google\Cloud\Spanner\ArrayType` or `Google\Cloud\Spanner\StructType`.'
            );
        }

        $child = null;
        if ($type instanceof StructType) {
            $child = $type;
            $type = Database::TYPE_STRUCT;
        } elseif ($type instanceof ArrayType) {
            $child = $type;
            $type = Database::TYPE_ARRAY;
        }

        if (!in_array($type, ValueMapper::$allowedTypes)) {
            throw new \InvalidArgumentException(sprintf(
                'Field type `%s` is not valid.',
                $type
            ));
        }

        $this->fields[] = [
            'name' => $name,
            'type' => $type,
            'child' => $child
        ];

        return $this;
    }
public function add($name, $type)
    {
        $invalidIntTypes = [
            Database::TYPE_STRUCT,
            Database::TYPE_ARRAY
        ];

        if (is_int($type) && in_array($type, $invalidIntTypes)) {
            throw new \InvalidArgumentException(
                '`Database::TYPE_ARRAY` and `Database::TYPE_STRUCT` are not valid as struct types. ' .
                'Instead provide `Google\Cloud\Spanner\ArrayType` or `Google\Cloud\Spanner\StructType`.'
            );
        }

        $child = null;
        if ($type instanceof StructType) {
            $child = $type;
            $type = Database::TYPE_STRUCT;
        } elseif ($type instanceof ArrayType) {
            $child = $type;
            $type = Database::TYPE_ARRAY;
        }

        if (!in_array($type, ValueMapper::$allowedTypes)) {
            throw new \InvalidArgumentException(sprintf(
                'Field type `%s` is not valid.',
                $type
            ));
        }

        $this->fields[] = [
            'name' => $name,
            'type' => $type,
            'child' => $child
        ];

        return $this;
    }
public function add ( $ name , $ type ) { $ invalidIntTypes = [ Database :: TYPE_STRUCT , Database :: TYPE_ARRAY ] ; if ( is_int ( $ type ) && in_array ( $ type , $ invalidIntTypes ) ) { throw new \ InvalidArgumentException ( '`Database::TYPE_ARRAY` and `Database::TYPE_STRUCT` are not valid as struct types. ' . 'Instead provide `Google\Cloud\Spanner\ArrayType` or `Google\Cloud\Spanner\StructType`.' ) ; } $ child = null ; if ( $ type instanceof StructType ) { $ child = $ type ; $ type = Database :: TYPE_STRUCT ; } elseif ( $ type instanceof ArrayType ) { $ child = $ type ; $ type = Database :: TYPE_ARRAY ; } if ( ! in_array ( $ type , ValueMapper :: $ allowedTypes ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Field type `%s` is not valid.' , $ type ) ) ; } $ this -> fields [ ] = [ 'name' => $ name , 'type' => $ type , 'child' => $ child ] ; return $ this ; }
Add a struct field definition.

Unnamed struct fields may be defined by providing `null` as the first
argument value, however you may find it more convenient to use the provided
{@see Google\Cloud\Spanner\StructType::addUnnamed()} method.

Example:
```
$structType->add('firstName', Database::TYPE_STRING);
```

```
// If a field is a struct or array, it must be explicitly defined.
use Google\Cloud\Spanner\ArrayType;
use Google\Cloud\Spanner\Database;
use Google\Cloud\Spanner\StructType;

// Create a struct which will be nested later.
$customer = (new StructType)
->add('name', Database::TYPE_STRING)
->add('phone', Database::TYPE_STRING)
->add('email', Database::TYPE_STRING)
->add('lastOrderDate', Database::TYPE_DATE);

// Create an array to nest within the customer type definition.
$orderIds = new ArrayType(Database::TYPE_INT64);
$customer->add('orderIds', $orderIds);

// Add the customer definition to the parameter definition.
$structType->add('customer', $customer);
```

@param string|null $name The field name.
@param int|ArrayType|StructType $type $type A value type code or nested
struct or array definition. Accepted integer values are defined as
constants on {@see Google\Cloud\Spanner\Database}, and are as
follows: `Database::TYPE_BOOL`, `Database::TYPE_INT64`,
`Database::TYPE_FLOAT64`, `Database::TYPE_TIMESTAMP`,
`Database::TYPE_DATE`, `Database::TYPE_STRING` and
`Database::TYPE_BYTES`
@return StructType The current instance, for chaining additional field
definitions.
@throws \InvalidArgumentException If an invalid type is provided.
Add a struct field definition .