Spanner/src/TransactionConfigurationTrait.php
private function configureSnapshotOptions(array &$options, array $previous = [])
    {
        $options += [
            'singleUse' => false,
            'returnReadTimestamp' => null,
            'strong' => null,
            'readTimestamp' => null,
            'exactStaleness' => null,
            'minReadTimestamp' => null,
            'maxStaleness' => null,
        ];

        $previousOptions = isset($previous['transactionOptions']['readOnly'])
            ? $previous['transactionOptions']['readOnly']
            : [];

        // These are only available in single-use transactions.
        if (!$options['singleUse'] && ($options['maxStaleness'] || $options['minReadTimestamp'])) {
            throw new \BadMethodCallException(
                'maxStaleness and minReadTimestamp are only available in single-use transactions.'
            );
        }

        $transactionOptions = [
            'readOnly' => $this->arrayFilterRemoveNull([
                'returnReadTimestamp' => $this->pluck('returnReadTimestamp', $options),
                'strong' => $this->pluck('strong', $options),
                'minReadTimestamp' => $this->pluck('minReadTimestamp', $options),
                'maxStaleness' => $this->pluck('maxStaleness', $options),
                'readTimestamp' => $this->pluck('readTimestamp', $options),
                'exactStaleness' => $this->pluck('exactStaleness', $options),
            ]) + $previousOptions
        ];

        if (empty($transactionOptions['readOnly'])) {
            $transactionOptions['readOnly']['strong'] = true;
        }

        $timestampFields = [
            'minReadTimestamp',
            'readTimestamp'
        ];

        $durationFields = [
            'exactStaleness',
            'maxStaleness'
        ];

        foreach ($timestampFields as $tsf) {
            if (isset($transactionOptions['readOnly'][$tsf]) && !isset($previousOptions[$tsf])) {
                $field = $transactionOptions['readOnly'][$tsf];
                if (!($field instanceof Timestamp)) {
                    throw new \BadMethodCallException(sprintf(
                        'Read Only Transaction Configuration Field %s must be an instance of `%s`.',
                        $tsf,
                        Timestamp::class
                    ));
                }

                $transactionOptions['readOnly'][$tsf] = $field->formatAsString();
            }
        }

        foreach ($durationFields as $df) {
            if (isset($transactionOptions['readOnly'][$df]) && !isset($previousOptions[$df])) {
                $field = $transactionOptions['readOnly'][$df];
                if (!($field instanceof Duration)) {
                    throw new \BadMethodCallException(sprintf(
                        'Read Only Transaction Configuration Field %s must be an instance of `%s`.',
                        $df,
                        Duration::class
                    ));
                }

                $transactionOptions['readOnly'][$df] = $field->get();
            }
        }

        return $transactionOptions;
    }
private function configureSnapshotOptions(array &$options, array $previous = [])
    {
        $options += [
            'singleUse' => false,
            'returnReadTimestamp' => null,
            'strong' => null,
            'readTimestamp' => null,
            'exactStaleness' => null,
            'minReadTimestamp' => null,
            'maxStaleness' => null,
        ];

        $previousOptions = isset($previous['transactionOptions']['readOnly'])
            ? $previous['transactionOptions']['readOnly']
            : [];

        // These are only available in single-use transactions.
        if (!$options['singleUse'] && ($options['maxStaleness'] || $options['minReadTimestamp'])) {
            throw new \BadMethodCallException(
                'maxStaleness and minReadTimestamp are only available in single-use transactions.'
            );
        }

        $transactionOptions = [
            'readOnly' => $this->arrayFilterRemoveNull([
                'returnReadTimestamp' => $this->pluck('returnReadTimestamp', $options),
                'strong' => $this->pluck('strong', $options),
                'minReadTimestamp' => $this->pluck('minReadTimestamp', $options),
                'maxStaleness' => $this->pluck('maxStaleness', $options),
                'readTimestamp' => $this->pluck('readTimestamp', $options),
                'exactStaleness' => $this->pluck('exactStaleness', $options),
            ]) + $previousOptions
        ];

        if (empty($transactionOptions['readOnly'])) {
            $transactionOptions['readOnly']['strong'] = true;
        }

        $timestampFields = [
            'minReadTimestamp',
            'readTimestamp'
        ];

        $durationFields = [
            'exactStaleness',
            'maxStaleness'
        ];

        foreach ($timestampFields as $tsf) {
            if (isset($transactionOptions['readOnly'][$tsf]) && !isset($previousOptions[$tsf])) {
                $field = $transactionOptions['readOnly'][$tsf];
                if (!($field instanceof Timestamp)) {
                    throw new \BadMethodCallException(sprintf(
                        'Read Only Transaction Configuration Field %s must be an instance of `%s`.',
                        $tsf,
                        Timestamp::class
                    ));
                }

                $transactionOptions['readOnly'][$tsf] = $field->formatAsString();
            }
        }

        foreach ($durationFields as $df) {
            if (isset($transactionOptions['readOnly'][$df]) && !isset($previousOptions[$df])) {
                $field = $transactionOptions['readOnly'][$df];
                if (!($field instanceof Duration)) {
                    throw new \BadMethodCallException(sprintf(
                        'Read Only Transaction Configuration Field %s must be an instance of `%s`.',
                        $df,
                        Duration::class
                    ));
                }

                $transactionOptions['readOnly'][$df] = $field->get();
            }
        }

        return $transactionOptions;
    }
private function configureSnapshotOptions ( array & $ options , array $ previous = [ ] ) { $ options += [ 'singleUse' => false , 'returnReadTimestamp' => null , 'strong' => null , 'readTimestamp' => null , 'exactStaleness' => null , 'minReadTimestamp' => null , 'maxStaleness' => null , ] ; $ previousOptions = isset ( $ previous [ 'transactionOptions' ] [ 'readOnly' ] ) ? $ previous [ 'transactionOptions' ] [ 'readOnly' ] : [ ] ; // These are only available in single-use transactions. if ( ! $ options [ 'singleUse' ] && ( $ options [ 'maxStaleness' ] || $ options [ 'minReadTimestamp' ] ) ) { throw new \ BadMethodCallException ( 'maxStaleness and minReadTimestamp are only available in single-use transactions.' ) ; } $ transactionOptions = [ 'readOnly' => $ this -> arrayFilterRemoveNull ( [ 'returnReadTimestamp' => $ this -> pluck ( 'returnReadTimestamp' , $ options ) , 'strong' => $ this -> pluck ( 'strong' , $ options ) , 'minReadTimestamp' => $ this -> pluck ( 'minReadTimestamp' , $ options ) , 'maxStaleness' => $ this -> pluck ( 'maxStaleness' , $ options ) , 'readTimestamp' => $ this -> pluck ( 'readTimestamp' , $ options ) , 'exactStaleness' => $ this -> pluck ( 'exactStaleness' , $ options ) , ] ) + $ previousOptions ] ; if ( empty ( $ transactionOptions [ 'readOnly' ] ) ) { $ transactionOptions [ 'readOnly' ] [ 'strong' ] = true ; } $ timestampFields = [ 'minReadTimestamp' , 'readTimestamp' ] ; $ durationFields = [ 'exactStaleness' , 'maxStaleness' ] ; foreach ( $ timestampFields as $ tsf ) { if ( isset ( $ transactionOptions [ 'readOnly' ] [ $ tsf ] ) && ! isset ( $ previousOptions [ $ tsf ] ) ) { $ field = $ transactionOptions [ 'readOnly' ] [ $ tsf ] ; if ( ! ( $ field instanceof Timestamp ) ) { throw new \ BadMethodCallException ( sprintf ( 'Read Only Transaction Configuration Field %s must be an instance of `%s`.' , $ tsf , Timestamp :: class ) ) ; } $ transactionOptions [ 'readOnly' ] [ $ tsf ] = $ field -> formatAsString ( ) ; } } foreach ( $ durationFields as $ df ) { if ( isset ( $ transactionOptions [ 'readOnly' ] [ $ df ] ) && ! isset ( $ previousOptions [ $ df ] ) ) { $ field = $ transactionOptions [ 'readOnly' ] [ $ df ] ; if ( ! ( $ field instanceof Duration ) ) { throw new \ BadMethodCallException ( sprintf ( 'Read Only Transaction Configuration Field %s must be an instance of `%s`.' , $ df , Duration :: class ) ) ; } $ transactionOptions [ 'readOnly' ] [ $ df ] = $ field -> get ( ) ; } } return $ transactionOptions ; }
Configure a Read-Only transaction.

@param array $options Configuration Options.
@param array $previous Previously given call options (for single-use snapshots).
@return array
Configure a Read - Only transaction .