Exemplo n.º 1
0
 public function testGetCloseQuotesFor()
 {
     $quoter = new \r8\Quoter();
     $quoter->setQuote("(", ")");
     $quoter->setQuote("`");
     $quoter->setQuote("!", array('@', '#', '*'));
     $this->assertEquals(array(')'), $quoter->getCloseQuotesFor("("));
     $this->assertEquals(array('@', '#', '*'), $quoter->getCloseQuotesFor("!"));
 }
Exemplo n.º 2
0
 /**
  * Cleans up a SQL query for comparison
  *
  * @param String $sql The SQL to clean
  * @return String
  */
 public static function cleanSQL($sql)
 {
     $quoter = new \r8\Quoter();
     $quoter->setQuote('"')->setQuote("'")->setQuote("`");
     $parsed = $quoter->parse($sql);
     $parsed->setIncludeQuoted(FALSE)->setIncludeUnquoted(TRUE);
     $keywords = '/\\b(?:' . implode("|", self::$keywords) . ')\\b/i';
     $breaks = '/\\b(' . implode("|", self::$breaks) . ')\\b/i';
     $parsed->filter(new \r8\Filter\Chain(r8(new \r8\Curry\Call('str_replace'))->setLeft(array("\n", "\r"), " "), r8(new \r8\Curry\Call('\\r8\\str\\stripRepeats'))->setRight(" "), r8(new \r8\Curry\Call('preg_replace_callback'))->setLeft($keywords, function ($value) {
         return strtoupper($value[0]);
     }), r8(new \r8\Curry\Call('preg_replace'))->setLeft($breaks, "\n\\1")));
     return trim($parsed->__toString(), " ;");
 }