2019-03-28 18:12:39 +08:00

92 lines
1.4 KiB
PHP

<?php
namespace Dipper\Foundation\Debugger\Queries;
class Output
{
/**
* @var string
*/
public $output = '';
/**
* @var
*/
private $event;
/**
* Output constructor.
*/
public function __construct($event)
{
$this->event = $event;
}
/**
* @return string
*/
protected function set($text)
{
return $this->output = $text;
}
/**
* @return string
*/
public function get()
{
return $this->output;
}
/**
* @void
*/
public function clear()
{
$this->set('');
}
/**
* Add line to indicate new query
*
* @void
*/
public function newQuery()
{
$this->append('----------------- NEW Query -----------------');
}
/**
* Add empty line
*
* @void
*/
public function spaceLine()
{
$this->append("\n \n");
}
/**
* Add sql query data
*
* @return void
*/
public function sql()
{
$fullQuery = vsprintf(str_replace(['%', '?'], ['%%', "'%s'"], $this->event->sql), $this->event->bindings);
$result = $this->event->connectionName . ' (' . $this->event->time . '): ' . $fullQuery;
$this->append($result);
}
/**
* @param $output
*
* @return string
*/
private function append($output)
{
return $this->output .= $output;
}
}