WhenThenExpression
in package
implements
ExpressionInterface
uses
CaseExpressionTrait, ExpressionTypeCasterTrait
Represents a SQL when/then clause with a fluid API
Table of Contents
Interfaces
- ExpressionInterface
- An interface used by Expression objects.
Properties
- $_typeMap : TypeMap
- The type map to use when using an array of conditions for the `WHEN` value.
- $hasThenBeenDefined : bool
- Whether the `THEN` value has been defined, eg whether `then()` has been invoked.
- $then : ExpressionInterface|object|scalar|null
- The `THEN` value.
- $thenType : string|null
- The `THEN` result type.
- $validClauseNames : array<string|int, string>
- The names of the clauses that are valid for use with the `clause()` method.
- $when : ExpressionInterface|object|scalar|null
- Then `WHEN` value.
- $whenType : array<string|int, mixed>|string|null
- The `WHEN` value type.
Methods
- __clone() : void
- Clones the inner expression objects.
- __construct() : mixed
- Constructor.
- clause() : ExpressionInterface|object|scalar|null
- Returns the available data for the given clause.
- getResultType() : string|null
- Returns the expression's result value type.
- sql() : string
- Converts the Node into a SQL string fragment.
- then() : $this
- Sets the `THEN` result value.
- traverse() : $this
- Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
- when() : $this
- Sets the `WHEN` value.
- _castToExpression() : mixed
- Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
- _requiresToExpressionCasting() : array<string|int, mixed>
- Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
Properties
$_typeMap
The type map to use when using an array of conditions for the `WHEN` value.
protected
TypeMap
$_typeMap
$hasThenBeenDefined
Whether the `THEN` value has been defined, eg whether `then()` has been invoked.
protected
bool
$hasThenBeenDefined
= false
$then
The `THEN` value.
protected
ExpressionInterface|object|scalar|null
$then
= null
$thenType
The `THEN` result type.
protected
string|null
$thenType
= null
$validClauseNames
The names of the clauses that are valid for use with the `clause()` method.
protected
array<string|int, string>
$validClauseNames
= ['when', 'then']
$when
Then `WHEN` value.
protected
ExpressionInterface|object|scalar|null
$when
= null
$whenType
The `WHEN` value type.
protected
array<string|int, mixed>|string|null
$whenType
= null
Methods
__clone()
Clones the inner expression objects.
public
__clone() : void
__construct()
Constructor.
public
__construct([TypeMap|null $typeMap = null ]) : mixed
Parameters
- $typeMap : TypeMap|null = null
-
The type map to use when using an array of conditions for the
WHEN
value.
clause()
Returns the available data for the given clause.
public
clause(string $clause) : ExpressionInterface|object|scalar|null
Available clauses
The following clause names are available:
-
when
: TheWHEN
value. -
then
: TheTHEN
result value.
Parameters
- $clause : string
-
The name of the clause to obtain.
Tags
Return values
ExpressionInterface|object|scalar|nullgetResultType()
Returns the expression's result value type.
public
getResultType() : string|null
Tags
Return values
string|nullsql()
Converts the Node into a SQL string fragment.
public
sql(ValueBinder $binder) : string
Parameters
- $binder : ValueBinder
-
Parameter binder
Tags
Return values
stringthen()
Sets the `THEN` result value.
public
then(ExpressionInterface|object|scalar|null $result[, string|null $type = null ]) : $this
Parameters
- $result : ExpressionInterface|object|scalar|null
-
The result value.
- $type : string|null = null
-
The result type. If no type is provided, the type will be inferred from the given result value.
Return values
$thistraverse()
Iterates over each part of the expression recursively for every level of the expressions tree and executes the $callback callable passing as first parameter the instance of the expression currently being iterated.
public
traverse(Closure $callback) : $this
Parameters
- $callback : Closure
-
The callable to apply to all nodes.
Tags
Return values
$thiswhen()
Sets the `WHEN` value.
public
when(ExpressionInterface|object|array<string|int, mixed>|scalar $when[, array<string, string>|string|null $type = null ]) : $this
Parameters
- $when : ExpressionInterface|object|array<string|int, mixed>|scalar
-
The
WHEN
value. 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$type
argument (which forces the$when
value 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! - $type : array<string, string>|string|null = null
-
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.
Tags
Return values
$this_castToExpression()
Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
protected
_castToExpression(mixed $value[, string|null $type = null ]) : mixed
Parameters
- $value : mixed
-
The value to convert to ExpressionInterface
- $type : string|null = null
-
The type name
_requiresToExpressionCasting()
Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
protected
_requiresToExpressionCasting(array<string|int, mixed> $types) : array<string|int, mixed>
Parameters
- $types : array<string|int, mixed>
-
List of type names