3 final class PhutilQueryString
extends Phobject
{
6 private $unmaskedString;
8 public function __construct(PhutilQsprintfInterface
$escaper, array $argv) {
9 // Immediately render the query into a static scalar value.
11 // This makes sure we throw immediately if there are errors in the
12 // parameters, which is much better than throwing later on.
14 // This also makes sure that later mutations to objects passed as
15 // parameters won't affect the outcome. Consider:
17 // $object->setTableName('X');
18 // $query = qsprintf($conn, '%R', $object);
19 // $object->setTableName('Y');
21 // We'd like "$query" to reference "X", reflecting the object as it
22 // existed when it was passed to "qsprintf(...)". It's surprising if the
23 // modification to the object after "qsprintf(...)" can affect "$query".
25 $masked_string = xsprintf(
28 'escaper' => $escaper,
33 $unmasked_string = xsprintf(
36 'escaper' => $escaper,
41 $this->maskedString
= $masked_string;
42 $this->unmaskedString
= $unmasked_string;
45 public function __toString() {
46 return $this->getMaskedString();
49 public function getUnmaskedString() {
50 return $this->unmaskedString
;
53 public function getMaskedString() {
54 return $this->maskedString
;