API / Minn\Runtime / Placeholders

Placeholders final class

Minn\Runtime\Placeholders · public/minn/src/Minn/Runtime/Placeholders.php · 71 lines

The printf placeholders plugin code hands wpdb::prepare, filled the way the reference fills them: a bare %s is escaped and quoted; a numbered (%1$s), padded (%5s) or precise (%.2f) one is formatted and escaped but never quoted, so a plugin can name a table with it; %d and %f cast; %i backticks an identifier; %% is a literal. Numbered placeholders address the argument list directly while unnumbered ones count from the first on their own, as vsprintf does. A placeholder with no argument behind it empties the whole query, as the reference does.

Constants and properties

privateSPEC = '/%(?:(\\d+)\\$)?([-+ 0]*)(\\d*)(?:\\.(\\d+))?([sdfFi%])/'

Public

staticfill(string $query, array $args, callable $escape): ?string#

Fills a query's placeholders from the arguments; null when one has no argument.

$argslist<mixed>
$escapecallable(string): stringthe connection's string escape
staticprepare(string $query, array $args, callable $escape): array#

fill() with what wpdb::prepare reports alongside: how many placeholders the query has (%% not among them) and the type of each argument it could not use (an array or an object fills as '').

$argslist<mixed>
$escapecallable(string): stringthe connection's string escape
@return array{query: ?string, placeholders: int, unsupported: list<string>}

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatefilled(string $query, array $args, callable $escape): ?string#
$argslist<mixed>
privatequoted(string $placeholder, string $escaped): string#

A bare %s is the one placeholder the reference wraps in quotes.

privatetext(mixed $value): string#