mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 14:46:50 +02:00
@@ -57,7 +57,7 @@ class Event
|
|||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->sql = trim($sql);
|
$this->sql = trim((string) $sql);
|
||||||
$this->time = -microtime(true);
|
$this->time = -microtime(true);
|
||||||
|
|
||||||
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
||||||
|
@@ -22,11 +22,11 @@ class Helpers
|
|||||||
* Prints out a syntax highlighted version of the SQL command or Result.
|
* Prints out a syntax highlighted version of the SQL command or Result.
|
||||||
* @param string|Result
|
* @param string|Result
|
||||||
*/
|
*/
|
||||||
public static function dump($sql = null, bool $return = false): string
|
public static function dump($sql = null, bool $return = false): ?string
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
if ($sql instanceof Result && PHP_SAPI === 'cli') {
|
if ($sql instanceof Result && PHP_SAPI === 'cli') {
|
||||||
$hasColors = (substr(getenv('TERM'), 0, 5) === 'xterm');
|
$hasColors = (substr((string) getenv('TERM'), 0, 5) === 'xterm');
|
||||||
$maxLen = 0;
|
$maxLen = 0;
|
||||||
foreach ($sql as $i => $row) {
|
foreach ($sql as $i => $row) {
|
||||||
if ($i === 0) {
|
if ($i === 0) {
|
||||||
@@ -88,7 +88,7 @@ class Helpers
|
|||||||
// syntax highlight
|
// syntax highlight
|
||||||
$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";
|
$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";
|
||||||
if (PHP_SAPI === 'cli') {
|
if (PHP_SAPI === 'cli') {
|
||||||
if (substr(getenv('TERM'), 0, 5) === 'xterm') {
|
if (substr((string) getenv('TERM'), 0, 5) === 'xterm') {
|
||||||
$sql = preg_replace_callback($highlighter, function ($m) {
|
$sql = preg_replace_callback($highlighter, function ($m) {
|
||||||
if (!empty($m[1])) { // comment
|
if (!empty($m[1])) { // comment
|
||||||
return "\033[1;30m" . $m[1] . "\033[0m";
|
return "\033[1;30m" . $m[1] . "\033[0m";
|
||||||
@@ -130,6 +130,7 @@ class Helpers
|
|||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
} else {
|
} else {
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ class Result implements IDataSource
|
|||||||
/** @var bool Already fetched? Used for allowance for first seek(0) */
|
/** @var bool Already fetched? Used for allowance for first seek(0) */
|
||||||
private $fetched = false;
|
private $fetched = false;
|
||||||
|
|
||||||
/** @var string returned object class */
|
/** @var ?string returned object class */
|
||||||
private $rowClass = Row::class;
|
private $rowClass = Row::class;
|
||||||
|
|
||||||
/** @var callable returned object factory*/
|
/** @var callable returned object factory*/
|
||||||
@@ -133,7 +133,7 @@ class Result implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Set fetched object class. This class should extend the Row class.
|
* Set fetched object class. This class should extend the Row class.
|
||||||
*/
|
*/
|
||||||
public function setRowClass(string $class): self
|
public function setRowClass(?string $class): self
|
||||||
{
|
{
|
||||||
$this->rowClass = $class;
|
$this->rowClass = $class;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -143,7 +143,7 @@ class Result implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Returns fetched object class name.
|
* Returns fetched object class name.
|
||||||
*/
|
*/
|
||||||
public function getRowClass(): string
|
public function getRowClass(): ?string
|
||||||
{
|
{
|
||||||
return $this->rowClass;
|
return $this->rowClass;
|
||||||
}
|
}
|
||||||
|
@@ -67,7 +67,7 @@ class dibi
|
|||||||
* Creates a new Connection object and connects it to specified database.
|
* Creates a new Connection object and connects it to specified database.
|
||||||
* @throws Dibi\Exception
|
* @throws Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public static function connect(array $config = [], string $name = '0'): Dibi\Connection
|
public static function connect($config = [], string $name = '0'): Dibi\Connection
|
||||||
{
|
{
|
||||||
return self::$connection = self::$registry[$name] = new Dibi\Connection($config, $name);
|
return self::$connection = self::$registry[$name] = new Dibi\Connection($config, $name);
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ class dibi
|
|||||||
* @param string|Result
|
* @param string|Result
|
||||||
* @param bool return output instead of printing it?
|
* @param bool return output instead of printing it?
|
||||||
*/
|
*/
|
||||||
public static function dump($sql = null, bool $return = false): string
|
public static function dump($sql = null, bool $return = false): ?string
|
||||||
{
|
{
|
||||||
return Dibi\Helpers::dump($sql, $return);
|
return Dibi\Helpers::dump($sql, $return);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user