driver instanceof Sqlserver) { return $p ? '1' : '0'; } return $p ? 'TRUE' : 'FALSE'; } if (is_string($p)) { // Likely binary data like a blob or binary uuid. // pattern matches ascii control chars. if (preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u', '', $p) !== $p) { $p = bin2hex($p); } $replacements = [ '$' => '\\$', '\\' => '\\\\\\\\', "'" => "''", ]; $p = strtr($p, $replacements); return "'{$p}'"; } return $p; }, $this->params); $keys = []; $limit = is_int(key($params)) ? 1 : -1; foreach ($params as $key => $param) { $keys[] = is_string($key) ? "/:{$key}\b/" : '/[?]/'; } return (string)preg_replace($keys, $params, $this->query, $limit); } /** * Get the logging context data for a query. * * @return array */ public function getContext(): array { return [ 'query' => $this->query, 'numRows' => $this->numRows, 'took' => $this->took, 'role' => $this->driver ? $this->driver->getRole() : '', ]; } /** * Set logging context for this query. * * @param array $context Context data. * @return void */ public function setContext(array $context): void { foreach ($context as $key => $val) { if (property_exists($this, $key)) { $this->{$key} = $val; } } } /** * Returns data that will be serialized as JSON * * @return array */ public function jsonSerialize(): array { $error = $this->error; if ($error !== null) { $error = [ 'class' => $error::class, 'message' => $error->getMessage(), 'code' => $error->getCode(), ]; } return [ 'query' => $this->query, 'numRows' => $this->numRows, 'params' => $this->params, 'took' => $this->took, 'error' => $error, ]; } /** * Returns the string representation of this logged query * * @return string */ public function __toString(): string { if ($this->params) { return $this->interpolate(); } return $this->query; } }