예제 #1
0
 public function testReplaceQueryParametersWithPostgresCasting()
 {
     $extension = new DoctrineExtension();
     $query = 'a=? OR (1)::string OR b=?';
     $parameters = array(1, 2);
     $result = $extension->replaceQueryParameters($query, $parameters, false);
     $this->assertEquals('a=1 OR (1)::string OR b=2', $result);
 }
예제 #2
0
 /**
  * Return a query with the parameters replaced
  *
  * @param string $query
  * @param array $parameters
  *
  * @return string
  */
 public function replaceQueryParameters($query, $parameters)
 {
     $i = 0;
     $result = preg_replace_callback('/\\?|(:[a-z0-9_]+)/i', function ($matches) use($parameters, &$i) {
         $key = substr($matches[0], 1);
         if (!isset($parameters[$i]) && !isset($parameters[$key])) {
             return $matches[0];
         }
         $value = isset($parameters[$i]) ? $parameters[$i] : $parameters[$key];
         $result = DoctrineExtension::escapeFunction($value);
         $i++;
         return $result;
     }, $query);
     $result = \SqlFormatter::highlight($result);
     $result = str_replace(array("<pre ", "</pre>"), array("<span ", "</span>"), $result);
     return $result;
 }