JsonContains
extends AbstractPredicate
in package
Json Contains predicate class
Tags
Table of Contents
Properties
- $candidate : mixed
- Candidate value to test for containment
- $conjunction : string
- Conjunction
- $format : string|null
- Format
- $hasCandidate : bool
- Flag denoting whether a candidate value was supplied
- $values : mixed
- Values
Methods
- __construct() : mixed
- Constructor
- getCandidate() : mixed
- Get the candidate value
- getConjunction() : string
- Get the conjunction
- getFormat() : string
- Get the format
- getValues() : mixed
- Get the values
- hasCandidate() : bool
- Determine if a candidate value was supplied
- render() : string
- Render the predicate string
- setConjunction() : AbstractPredicate
- Get the conjunction
- setValues() : AbstractPredicate
- Set values
- assertNoSubqueryAlias() : void
- Assert that a nested Sql instance used as a subquery value has no alias set.
- renderJsonValue() : string
- Render a JSON path comparison value
- renderValue() : string
- Render a single predicate value: a nested Select/Sql instance embeds as a parenthesized subquery, anything else quotes as a literal/placeholder as before
Properties
$candidate
Candidate value to test for containment
protected
mixed
$candidate
= null
Deliberately stored OUTSIDE of $this->values: the containment candidate is a raw PHP value that gets json_encode()'d verbatim at render time, never a bound-parameter placeholder token. PredicateSet::addPredicate() walks every element of a predicate's $values array through AbstractSql::isParameter()/getParameter(), which would silently rewrite candidates such as true, '?', '$1' (or arrays containing them) into a dialect placeholder token - corrupting the rendered SQL and, on PostgreSQL, desyncing the parameter-number sequence for unrelated sibling predicates. Keeping it off the values array keeps it out of that loop entirely.
$conjunction
Conjunction
protected
string
$conjunction
= 'AND'
$format
Format
protected
string|null
$format
= null
$hasCandidate
Flag denoting whether a candidate value was supplied
protected
bool
$hasCandidate
= false
$values
Values
protected
mixed
$values
= null
Methods
__construct()
Constructor
public
__construct(array<string|int, mixed> $values[, string $conjunction = 'AND' ]) : mixed
Instantiate the JSON CONTAINS predicate set object
Parameters
- $values : array<string|int, mixed>
- $conjunction : string = 'AND'
Tags
getCandidate()
Get the candidate value
public
getCandidate() : mixed
getConjunction()
Get the conjunction
public
getConjunction() : string
Return values
stringgetFormat()
Get the format
public
getFormat() : string
Return values
stringgetValues()
Get the values
public
getValues() : mixed
hasCandidate()
Determine if a candidate value was supplied
public
hasCandidate() : bool
Return values
boolrender()
Render the predicate string
public
render(AbstractSql $sql) : string
Parameters
- $sql : AbstractSql
Tags
Return values
stringsetConjunction()
Get the conjunction
public
setConjunction(string $conjunction) : AbstractPredicate
Parameters
- $conjunction : string
Tags
Return values
AbstractPredicatesetValues()
Set values
public
setValues(mixed $values) : AbstractPredicate
Parameters
- $values : mixed
Return values
AbstractPredicateassertNoSubqueryAlias()
Assert that a nested Sql instance used as a subquery value has no alias set.
protected
static assertNoSubqueryAlias(AbstractSql $value) : void
An aliased Select renders itself as "(SELECT ...) AS alias", which is only valid
in a FROM/JOIN context. Embedded inside a predicate it would produce silently
invalid SQL, so reject it up front with a clear error.
Parameters
- $value : AbstractSql
Tags
renderJsonValue()
Render a JSON path comparison value
protected
static renderJsonValue(AbstractSql $sql, string|null $column, mixed $value) : string
PostgreSQL's JSON extraction operators ('->>' / '#>>') always return text, and PostgreSQL has no implicit text-to-number comparison: a bare numeric literal on the right-hand side fails at execution time with "operator does not exist: text = integer". So on PostgreSQL a plain scalar value is forced to a quoted text literal, which compares correctly against the extracted text. Two cases must NOT be force-quoted and are handed to renderValue() unchanged: a nested Sql instance (which embeds as a parenthesized subquery), and a bound parameter placeholder token (which the database binds as text anyway).
Parameters
- $sql : AbstractSql
- $column : string|null
- $value : mixed
Tags
Return values
stringrenderValue()
Render a single predicate value: a nested Select/Sql instance embeds as a parenthesized subquery, anything else quotes as a literal/placeholder as before
protected
static renderValue(AbstractSql $sql, mixed $value) : string
Parameters
- $sql : AbstractSql
- $value : mixed