Class JsonPathExpression
Represents a JSON path expression with optional clauses for each json function.
Constants
-
ALLOWED_BEHAVIORS ¶
[self::BEHAVIOR_NULL, self::BEHAVIOR_ERROR, self::BEHAVIOR_DEFAULT, self::BEHAVIOR_UNKNOWN, self::BEHAVIOR_TRUE, self::BEHAVIOR_FALSE] -
BEHAVIOR_DEFAULT ¶
'DEFAULT' -
BEHAVIOR_ERROR ¶
'ERROR' -
BEHAVIOR_FALSE ¶
'FALSE' -
BEHAVIOR_NULL ¶
'NULL' -
BEHAVIOR_TRUE ¶
'TRUE' -
BEHAVIOR_UNKNOWN ¶
'UNKNOWN'
Property Summary
-
$onEmpty protected
array{behavior: string, value: mixed}|null -
$onError protected
array{behavior: string, value: mixed}|null -
$passing protected
array<string, array{value: mixed, type: (string|int|null)}> -
$returnType protected
stringThe type name this expression will return when executed
-
$returning protected
string|null
Method Summary
-
__construct() public
Constructs with base json path string.
-
behaviorSql() protected
Generates the SQL for ON EMPTY or ON ERROR clauses.
-
buildBehavior() protected
Validate and build behavior config.
-
getReturnType() public
Gets the type of the value this object will generate.
-
inferType() protected
Infers the abstract type for the given value.
-
onEmpty() public
Sets the ON EMPTY clause.
Not all database engines support every clause. Check for support before using.
-
onError() public
Sets the ON ERROR clause.
Not all database engines support every clause. Check for support before using.
-
passing() public
Sets the PASSING clause.
SQL Injection Warning: PASSING names are not sanitized before use.
Not all database engines support every clause. Check for support before using.
-
returning() public
Sets the RETURNING clause.
SQL Injection Warning: RETURNING type is not sanitized before use.
Not all database engines support every clause. Check for support before using.
-
setReturnType() public
Sets the type of the value this object will generate.
-
sql() public
Converts the Node into a SQL string fragment.
-
traverse() public
Iterates 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.
Method Detail
__construct() ¶ public
__construct(string $path)
Constructs with base json path string.
Parameters
-
string$path The json path
behaviorSql() ¶ protected
behaviorSql(string $origin, array $config, Cake\Database\ValueBinder $binder): string
Generates the SQL for ON EMPTY or ON ERROR clauses.
Parameters
-
string$origin The behavior origin.
-
array$config The behavior config.
-
Cake\Database\ValueBinder$binder The value binder.
Returns
stringbuildBehavior() ¶ protected
buildBehavior(string $behavior, mixed $value): array{behavior: string, value: mixed}
Validate and build behavior config.
Parameters
-
string$behavior The behavior name.
-
mixed$value The value if behavior is DEFAULT.
Returns
array{behavior: string, value: mixed}getReturnType() ¶ public
getReturnType(): string
Gets the type of the value this object will generate.
Returns
stringinferType() ¶ protected
inferType(mixed $value, Cake\Database\TypeMap|null $typeMap = null): string|null
Infers the abstract type for the given value.
Parameters
-
mixed$value The value for which to infer the type.
-
Cake\Database\TypeMap|null$typeMap optional Used to resolve the type of identifier expressions.
Returns
string|nullThe abstract type, or null if it could not be inferred.
onEmpty() ¶ public
onEmpty(self::BEHAVIOR_* $behavior, mixed $value = null): $this
Sets the ON EMPTY clause.
Not all database engines support every clause. Check for support before using.
Parameters
-
self::BEHAVIOR_*$behavior The behavior on empty (NULL, ERROR, or DEFAULT).
-
mixed$value optional The value if behavior is DEFAULT.
Returns
$thisonError() ¶ public
onError(self::BEHAVIOR_* $behavior, mixed $value = null): $this
Sets the ON ERROR clause.
Not all database engines support every clause. Check for support before using.
Parameters
-
self::BEHAVIOR_*$behavior The behavior on error (NULL, ERROR, or DEFAULT).
-
mixed$value optional The value if behavior is DEFAULT.
Returns
$thispassing() ¶ public
passing(array<string, string|int|float|bool> $passing, array<string, string|int> $types = []): $this
Sets the PASSING clause.
SQL Injection Warning: PASSING names are not sanitized before use.
Not all database engines support every clause. Check for support before using.
Parameters
-
array<string, string|int|float|bool>$passing Mapping of variable name to value.
-
array<string, string|int>$types optional Optional mapping of variable name to binding type.
Returns
$thisreturning() ¶ public
returning(string $type): $this
Sets the RETURNING clause.
SQL Injection Warning: RETURNING type is not sanitized before use.
Not all database engines support every clause. Check for support before using.
Parameters
-
string$type The sql data type to return
Returns
$thissetReturnType() ¶ public
setReturnType(string $type): $this
Sets the type of the value this object will generate.
Parameters
-
string$type The name of the type that is to be returned
Returns
$thissql() ¶ public
sql(Cake\Database\ValueBinder $binder): string
Converts the Node into a SQL string fragment.
Parameters
-
Cake\Database\ValueBinder$binder
Returns
stringtraverse() ¶ public
traverse(Closure $callback): $this
Iterates 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
$this