Path: blob/master/src/infrastructure/storage/xsprintf/PhutilQueryString.php
12241 views
<?php12final class PhutilQueryString extends Phobject {34private $maskedString;5private $unmaskedString;67public function __construct(PhutilQsprintfInterface $escaper, array $argv) {8// Immediately render the query into a static scalar value.910// This makes sure we throw immediately if there are errors in the11// parameters, which is much better than throwing later on.1213// This also makes sure that later mutations to objects passed as14// parameters won't affect the outcome. Consider:15//16// $object->setTableName('X');17// $query = qsprintf($conn, '%R', $object);18// $object->setTableName('Y');19//20// We'd like "$query" to reference "X", reflecting the object as it21// existed when it was passed to "qsprintf(...)". It's surprising if the22// modification to the object after "qsprintf(...)" can affect "$query".2324$masked_string = xsprintf(25'xsprintf_query',26array(27'escaper' => $escaper,28'unmasked' => false,29),30$argv);3132$unmasked_string = xsprintf(33'xsprintf_query',34array(35'escaper' => $escaper,36'unmasked' => true,37),38$argv);3940$this->maskedString = $masked_string;41$this->unmaskedString = $unmasked_string;42}4344public function __toString() {45return $this->getMaskedString();46}4748public function getUnmaskedString() {49return $this->unmaskedString;50}5152public function getMaskedString() {53return $this->maskedString;54}5556}575859