@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 57 lines 1.5 kB view raw
1<?php 2 3final class PhutilQueryString extends Phobject { 4 5 private $maskedString; 6 private $unmaskedString; 7 8 public function __construct(PhutilQsprintfInterface $escaper, array $argv) { 9 // Immediately render the query into a static scalar value. 10 11 // This makes sure we throw immediately if there are errors in the 12 // parameters, which is much better than throwing later on. 13 14 // This also makes sure that later mutations to objects passed as 15 // parameters won't affect the outcome. Consider: 16 // 17 // $object->setTableName('X'); 18 // $query = qsprintf($conn, '%R', $object); 19 // $object->setTableName('Y'); 20 // 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". 24 25 $masked_string = xsprintf( 26 'xsprintf_query', 27 array( 28 'escaper' => $escaper, 29 'unmasked' => false, 30 ), 31 $argv); 32 33 $unmasked_string = xsprintf( 34 'xsprintf_query', 35 array( 36 'escaper' => $escaper, 37 'unmasked' => true, 38 ), 39 $argv); 40 41 $this->maskedString = $masked_string; 42 $this->unmaskedString = $unmasked_string; 43 } 44 45 public function __toString() { 46 return $this->getMaskedString(); 47 } 48 49 public function getUnmaskedString() { 50 return $this->unmaskedString; 51 } 52 53 public function getMaskedString() { 54 return $this->maskedString; 55 } 56 57}