CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
      • Driver
      • Exception
      • Expression
      • Log
      • Query
      • Retry
      • Schema
      • Statement
      • Type
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class WhenThenExpression

Represents a SQL when/then clause with a fluid API

Namespace: Cake\Database\Expression

Property Summary

  • $_typeMap protected
    Cake\Database\TypeMap

    The type map to use when using an array of conditions for the WHEN value.

  • $hasThenBeenDefined protected
    bool

    Whether the THEN value has been defined, eg whether then() has been invoked.

  • $then protected
    Cake\Database\ExpressionInterface|object|scalar|null

    The THEN value.

  • $thenType protected
    string|null

    The THEN result type.

  • $validClauseNames protected
    array<string>

    The names of the clauses that are valid for use with the clause() method.

  • $when protected
    Cake\Database\ExpressionInterface|object|scalar|null

    Then WHEN value.

  • $whenType protected
    array|string|null

    The WHEN value type.

Method Summary

  • __clone() public

    Clones the inner expression objects.

  • __construct() public

    Constructor.

  • _castToExpression() protected

    Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.

  • _requiresToExpressionCasting() protected

    Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.

  • clause() public

    Returns the available data for the given clause.

  • compileNullableValue() protected

    Compiles a nullable value to SQL.

  • getResultType() public

    Returns the expression's result value type.

  • inferType() protected

    Infers the abstract type for the given value.

  • sql() public

    Converts the Node into a SQL string fragment.

  • then() public

    Sets the THEN result value.

  • traverse() public

    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() public

    Sets the WHEN value.

Method Detail

__clone() ¶ public

__clone(): void

Clones the inner expression objects.

Returns
void

__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 WHEN value.

_castToExpression() ¶ protected

_castToExpression(mixed $value, string|null $type = null): mixed

Conditionally 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): array

Returns 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
array

clause() ¶ public

clause(string $clause): Cake\Database\ExpressionInterface|object|scalar|null

Returns the available data for the given clause.

Available clauses

The following clause names are available:

  • when: The WHEN value.
  • then: The THEN result value.
Parameters
string $clause

The name of the clause to obtain.

Returns
Cake\Database\ExpressionInterface|object|scalar|null
Throws
InvalidArgumentException
In 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): string

Compiles 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
string

getResultType() ¶ public

getResultType(): string|null

Returns the expression's result value type.

Returns
string|null
See Also
WhenThenExpression::then()

inferType() ¶ protected

inferType(mixed $value): string|null

Infers the abstract type for the given value.

Parameters
mixed $value

The value for which to infer the type.

Returns
string|null

sql() ¶ public

sql(Cake\Database\ValueBinder $binder): string

Converts the Node into a SQL string fragment.

Parameters
Cake\Database\ValueBinder $binder
Returns
string

then() ¶ public

then(Cake\Database\ExpressionInterface|object|scalar|null $result, string|null $type = null): $this

Sets 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
$this

traverse() ¶ public

traverse(Closure $callback): $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.

Parameters
Closure $callback
Returns
$this

when() ¶ public

when(Cake\Database\ExpressionInterface|object|array|scalar $when, array<string, string>|string|null $type = null): $this

Sets the WHEN value.

Parameters
Cake\Database\ExpressionInterface|object|array|scalar $when

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!

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
$this
Throws
InvalidArgumentException
In case the `$when` argument is neither a non-empty array, nor a scalar value, an object, or an instance of `\Cake\Database\ExpressionInterface`.
InvalidArgumentException
In case the `$type` argument is neither an array, a string, nor null.
InvalidArgumentException
In case the `$when` argument is an array, and the `$type` argument is neither an array, nor null.
InvalidArgumentException
In case the `$when` argument is a non-array value, and the `$type` argument is neither a string, nor null.
See Also
CaseStatementExpression::when() for a more detailed usage explanation.

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

$then ¶ protected

The THEN value.

Type
Cake\Database\ExpressionInterface|object|scalar|null

$thenType ¶ protected

The THEN result type.

Type
string|null

$validClauseNames ¶ protected

The names of the clauses that are valid for use with the clause() method.

Type
array<string>

$when ¶ protected

Then WHEN value.

Type
Cake\Database\ExpressionInterface|object|scalar|null

$whenType ¶ protected

The WHEN value type.

Type
array|string|null
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs