['html'], 'deprecated' => true]), new TwigFilter('doctrine_prettify_sql', [$this, 'prettifySql'], ['is_safe' => ['html']]), new TwigFilter('doctrine_format_sql', [$this, 'formatSql'], ['is_safe' => ['html']]), new TwigFilter('doctrine_replace_query_parameters', [$this, 'replaceQueryParameters']), ]; } /** * Escape parameters of a SQL query * DON'T USE THIS FUNCTION OUTSIDE ITS INTENDED SCOPE * * @internal * * @param mixed $parameter * * @return string */ public static function escapeFunction($parameter) { $result = $parameter; switch (true) { // Check if result is non-unicode string using PCRE_UTF8 modifier case is_string($result) && ! preg_match('//u', $result): $result = '0x' . strtoupper(bin2hex($result)); break; case is_string($result): $result = "'" . addslashes($result) . "'"; break; case is_array($result): foreach ($result as &$value) { $value = static::escapeFunction($value); } $result = implode(', ', $result) ?: 'NULL'; break; case is_object($result) && method_exists($result, '__toString'): $result = addslashes($result->__toString()); break; case $result === null: $result = 'NULL'; break; case is_bool($result): $result = $result ? '1' : '0'; break; } return $result; } /** * Return a query with the parameters replaced * * @param string $query * @param mixed[]|Data $parameters * * @return string */ public function replaceQueryParameters($query, $parameters) { if ($parameters instanceof Data) { $parameters = $parameters->getValue(true); } $i = 0; if (! array_key_exists(0, $parameters) && array_key_exists(1, $parameters)) { $i = 1; } return preg_replace_callback( '/\?|((?setUpSqlFormatter(true, true); if ($highlightOnly) { return $this->sqlFormatter->highlight($sql); } return sprintf( '
%s