Documentation

JsonContains extends AbstractPredicate
in package

Json Contains predicate class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
7.0.0

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.

$hasCandidate

Flag denoting whether a candidate value was supplied

protected bool $hasCandidate = false

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
throws
Exception

getCandidate()

Get the candidate value

public getCandidate() : mixed

getConjunction()

Get the conjunction

public getConjunction() : string
Return values
string

hasCandidate()

Determine if a candidate value was supplied

public hasCandidate() : bool
Return values
bool

assertNoSubqueryAlias()

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
throws
Exception

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
throws
Exception
Return values
string

renderValue()

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
Tags
throws
Exception
Return values
string

        
On this page

Search results