Class WhenThenExpression
Represents a SQL when/then clause with a fluid API
Property Summary
- 
        $_typeMap protectedCake\Database\TypeMapThe type map to use when using an array of conditions for the WHENvalue.
- 
        $hasThenBeenDefined protectedboolWhether the THENvalue has been defined, eg whetherthen()has been invoked.
- 
        $then protectedCake\Database\ExpressionInterface|object|scalar|nullThe THENvalue.
- 
        $thenType protectedstring|nullThe THENresult type.
- 
        $validClauseNames protectedarray<string>The names of the clauses that are valid for use with the clause()method.
- 
        $when protectedCake\Database\ExpressionInterface|object|scalar|nullThen WHENvalue.
- 
        $whenType protectedarray|string|nullThe WHENvalue type.
Method Summary
- 
          __clone() publicClones the inner expression objects. 
- 
          __construct() publicConstructor. 
- 
          _castToExpression() protectedConditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified. 
- 
          _requiresToExpressionCasting() protectedReturns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter. 
- 
          clause() publicReturns the available data for the given clause. 
- 
          compileNullableValue() protectedCompiles a nullable value to SQL. 
- 
          getResultType() publicReturns the expression's result value type. 
- 
          inferType() protectedInfers the abstract type for the given value. 
- 
          sql() publicConverts the Node into a SQL string fragment. 
- 
          then() publicSets the THENresult value.
- 
          traverse() publicIterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated. 
- 
          when() publicSets the WHENvalue.
Method Detail
__construct() ¶ public
__construct(Cake\Database\TypeMap|null $typeMap = null)Constructor.
Parameters
- 
                Cake\Database\TypeMap|null$typeMap optional
- The type map to use when using an array of conditions for the - WHENvalue.
_castToExpression() ¶ protected
_castToExpression(mixed $value, string|null $type = null): mixedConditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
Parameters
- 
                mixed$value
- The value to convert to ExpressionInterface 
- 
                string|null$type optional
- The type name 
Returns
mixed_requiresToExpressionCasting() ¶ protected
_requiresToExpressionCasting(array $types): arrayReturns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
Parameters
- 
                array$types
- List of type names 
Returns
arrayclause() ¶ public
clause(string $clause): Cake\Database\ExpressionInterface|object|scalar|nullReturns the available data for the given clause.
Available clauses
The following clause names are available:
- when: The- WHENvalue.
- then: The- THENresult value.
Parameters
- 
                string$clause
- The name of the clause to obtain. 
Returns
Cake\Database\ExpressionInterface|object|scalar|nullThrows
InvalidArgumentExceptionIn case the given clause name is invalid.
compileNullableValue() ¶ protected
compileNullableValue(Cake\Database\ValueBinder $binder, Cake\Database\ExpressionInterface|object|scalar|null $value, string|null $type = null): stringCompiles a nullable value to SQL.
Parameters
- 
                Cake\Database\ValueBinder$binder
- The value binder to use. 
- 
                Cake\Database\ExpressionInterface|object|scalar|null$value
- The value to compile. 
- 
                string|null$type optional
- The value type. 
Returns
stringgetResultType() ¶ public
getResultType(): string|nullReturns the expression's result value type.
Returns
string|nullSee Also
inferType() ¶ protected
inferType(mixed $value): string|nullInfers the abstract type for the given value.
Parameters
- 
                mixed$value
- The value for which to infer the type. 
Returns
string|nullThe abstract type, or null if it could not be inferred.
sql() ¶ public
sql(Cake\Database\ValueBinder $binder): stringConverts the Node into a SQL string fragment.
Parameters
- 
                Cake\Database\ValueBinder$binder
Returns
stringthen() ¶ public
then(Cake\Database\ExpressionInterface|object|scalar|null $result, string|null $type = null): $thisSets the THEN result value.
Parameters
- 
                Cake\Database\ExpressionInterface|object|scalar|null$result
- The result value. 
- 
                string|null$type optional
- The result type. If no type is provided, the type will be inferred from the given result value. 
Returns
$thistraverse() ¶ public
traverse(Closure $callback): $thisIterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated.
Parameters
- 
                Closure$callback
Returns
$thiswhen() ¶ public
when(object|array|string|float|int|bool $when, array<string, string>|string|null $type = null): $thisSets the WHEN value.
Parameters
- 
                object|array|string|float|int|bool$when
- The - WHENvalue. When using an array of conditions, it must be compatible with- \Cake\Database\Query::where(). Note that this argument is not completely safe for use with user data, as a user supplied array would allow for raw SQL to slip in! If you plan to use user data, either pass a single type for the- $typeargument (which forces the- $whenvalue to be a non-array, and then always binds the data), use a conditions array where the user data is only passed on the value side of the array entries, or custom bindings!
- 
                array<string, string>|string|null$type optional
- The when value type. Either an associative array when using array style conditions, or else a string. If no type is provided, the type will be tried to be inferred from the value. 
Returns
$thisThrows
InvalidArgumentExceptionIn case the `$when` argument is an empty array.
InvalidArgumentExceptionIn case the `$when` argument is an array, and the `$type` argument is neither an array, nor null.
InvalidArgumentExceptionIn case the `$when` argument is a non-array value, and the `$type` argument is neither a string, nor null.
See Also
Property Detail
$_typeMap ¶ protected
The type map to use when using an array of conditions for the
WHEN value.
Type
Cake\Database\TypeMap$hasThenBeenDefined ¶ protected
Whether the THEN value has been defined, eg whether then()
has been invoked.
Type
bool$validClauseNames ¶ protected
The names of the clauses that are valid for use with the
clause() method.
Type
array<string>