vendor and env first commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\DataFormatter;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
class DataFormatter implements DataFormatterInterface
|
||||
{
|
||||
public $cloner;
|
||||
|
||||
public $dumper;
|
||||
|
||||
/**
|
||||
* DataFormatter constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->cloner = new VarCloner();
|
||||
$this->dumper = new CliDumper();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
public function formatVar($data)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
$this->dumper->dump(
|
||||
$this->cloner->cloneVar($data),
|
||||
function ($line, $depth) use (&$output) {
|
||||
// A negative depth means "end of dump"
|
||||
if ($depth >= 0) {
|
||||
// Adds a two spaces indentation to the line
|
||||
$output .= str_repeat(' ', $depth).$line."\n";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $seconds
|
||||
* @return string
|
||||
*/
|
||||
public function formatDuration($seconds)
|
||||
{
|
||||
if ($seconds < 0.001) {
|
||||
return round($seconds * 1000000) . 'μs';
|
||||
} elseif ($seconds < 0.1) {
|
||||
return round($seconds * 1000, 2) . 'ms';
|
||||
} elseif ($seconds < 1) {
|
||||
return round($seconds * 1000) . 'ms';
|
||||
}
|
||||
return round($seconds, 2) . 's';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $size
|
||||
* @param int $precision
|
||||
* @return string
|
||||
*/
|
||||
public function formatBytes($size, $precision = 2)
|
||||
{
|
||||
if ($size === 0 || $size === null) {
|
||||
return "0B";
|
||||
}
|
||||
|
||||
$sign = $size < 0 ? '-' : '';
|
||||
$size = abs($size);
|
||||
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
return $sign . round(pow(1024, $base - floor($base)), $precision) . $suffixes[(int) floor($base)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @return string
|
||||
*/
|
||||
public function formatClassName($object)
|
||||
{
|
||||
$class = \get_class($object);
|
||||
|
||||
if (false === ($pos = \strpos($class, "@anonymous\0"))) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
if (false === ($parent = \get_parent_class($class))) {
|
||||
return \substr($class, 0, $pos + 10);
|
||||
}
|
||||
|
||||
return $parent . '@anonymous';
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\DataFormatter;
|
||||
|
||||
/**
|
||||
* Formats data to be outputed as string
|
||||
*/
|
||||
interface DataFormatterInterface
|
||||
{
|
||||
/**
|
||||
* Transforms a PHP variable to a string representation
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return string
|
||||
*/
|
||||
function formatVar($data);
|
||||
|
||||
/**
|
||||
* Transforms a duration in seconds in a readable string
|
||||
*
|
||||
* @param float $seconds
|
||||
* @return string
|
||||
*/
|
||||
function formatDuration($seconds);
|
||||
|
||||
/**
|
||||
* Transforms a size in bytes to a human readable string
|
||||
*
|
||||
* @param string $size
|
||||
* @param integer $precision
|
||||
* @return string
|
||||
*/
|
||||
function formatBytes($size, $precision = 2);
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\DataFormatter;
|
||||
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataFormatter\VarDumper\DebugBarHtmlDumper;
|
||||
use Symfony\Component\VarDumper\Cloner\Data\SeekingData;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
/**
|
||||
* Clones and renders variables in HTML format using the Symfony VarDumper component.
|
||||
*
|
||||
* Cloning is decoupled from rendering, so that dumper users can have the fastest possible cloning
|
||||
* performance, while delaying rendering until it is actually needed.
|
||||
*/
|
||||
class DebugBarVarDumper implements AssetProvider
|
||||
{
|
||||
protected static $defaultClonerOptions = array();
|
||||
|
||||
protected static $defaultDumperOptions = array(
|
||||
'expanded_depth' => 0,
|
||||
'styles' => array(
|
||||
// NOTE: 'default' CSS is also specified in debugbar.css
|
||||
'default' => 'word-wrap: break-word; white-space: pre-wrap; word-break: normal',
|
||||
'num' => 'font-weight:bold; color:#1299DA',
|
||||
'const' => 'font-weight:bold',
|
||||
'str' => 'font-weight:bold; color:#3A9B26',
|
||||
'note' => 'color:#1299DA',
|
||||
'ref' => 'color:#7B7B7B',
|
||||
'public' => 'color:#000000',
|
||||
'protected' => 'color:#000000',
|
||||
'private' => 'color:#000000',
|
||||
'meta' => 'color:#B729D9',
|
||||
'key' => 'color:#3A9B26',
|
||||
'index' => 'color:#1299DA',
|
||||
'ellipsis' => 'color:#A0A000',
|
||||
),
|
||||
);
|
||||
|
||||
protected $clonerOptions;
|
||||
|
||||
protected $dumperOptions;
|
||||
|
||||
/** @var VarCloner */
|
||||
protected $cloner;
|
||||
|
||||
/** @var DebugBarHtmlDumper */
|
||||
protected $dumper;
|
||||
|
||||
/**
|
||||
* Gets the VarCloner instance with configuration options set.
|
||||
*
|
||||
* @return VarCloner
|
||||
*/
|
||||
protected function getCloner()
|
||||
{
|
||||
if (!$this->cloner) {
|
||||
$clonerOptions = $this->getClonerOptions();
|
||||
if (isset($clonerOptions['casters'])) {
|
||||
$this->cloner = new VarCloner($clonerOptions['casters']);
|
||||
} else {
|
||||
$this->cloner = new VarCloner();
|
||||
}
|
||||
if (isset($clonerOptions['additional_casters'])) {
|
||||
$this->cloner->addCasters($clonerOptions['additional_casters']);
|
||||
}
|
||||
if (isset($clonerOptions['max_items'])) {
|
||||
$this->cloner->setMaxItems($clonerOptions['max_items']);
|
||||
}
|
||||
if (isset($clonerOptions['max_string'])) {
|
||||
$this->cloner->setMaxString($clonerOptions['max_string']);
|
||||
}
|
||||
// setMinDepth was added to Symfony 3.4:
|
||||
if (isset($clonerOptions['min_depth']) && method_exists($this->cloner, 'setMinDepth')) {
|
||||
$this->cloner->setMinDepth($clonerOptions['min_depth']);
|
||||
}
|
||||
}
|
||||
return $this->cloner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DebugBarHtmlDumper instance with configuration options set.
|
||||
*
|
||||
* @return DebugBarHtmlDumper
|
||||
*/
|
||||
protected function getDumper()
|
||||
{
|
||||
if (!$this->dumper) {
|
||||
$this->dumper = new DebugBarHtmlDumper();
|
||||
$dumperOptions = $this->getDumperOptions();
|
||||
if (isset($dumperOptions['styles'])) {
|
||||
$this->dumper->setStyles($dumperOptions['styles']);
|
||||
}
|
||||
}
|
||||
return $this->dumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of non-default VarCloner configuration options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClonerOptions()
|
||||
{
|
||||
if ($this->clonerOptions === null) {
|
||||
$this->clonerOptions = self::$defaultClonerOptions;
|
||||
}
|
||||
return $this->clonerOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges an array of non-default VarCloner configuration options with the existing non-default
|
||||
* options.
|
||||
*
|
||||
* Configuration options are:
|
||||
* - casters: a map of VarDumper Caster objects to use instead of the default casters.
|
||||
* - additional_casters: a map of VarDumper Caster objects to use in addition to the default
|
||||
* casters.
|
||||
* - max_items: maximum number of items to clone beyond the minimum depth.
|
||||
* - max_string: maximum string size
|
||||
* - min_depth: minimum tree depth to clone before counting items against the max_items limit.
|
||||
* (Requires Symfony 3.4; ignored on older versions.)
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function mergeClonerOptions($options)
|
||||
{
|
||||
$this->clonerOptions = $options + $this->getClonerOptions();
|
||||
$this->cloner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the array of non-default VarCloner configuration options without retaining any of the
|
||||
* existing non-default options.
|
||||
*
|
||||
* Configuration options are:
|
||||
* - casters: a map of VarDumper Caster objects to use instead of the default casters.
|
||||
* - additional_casters: a map of VarDumper Caster objects to use in addition to the default
|
||||
* casters.
|
||||
* - max_items: maximum number of items to clone beyond the minimum depth.
|
||||
* - max_string: maximum string size
|
||||
* - min_depth: minimum tree depth to clone before counting items against the max_items limit.
|
||||
* (Requires Symfony 3.4; ignored on older versions.)
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function resetClonerOptions($options = null)
|
||||
{
|
||||
$this->clonerOptions = ($options ?: array()) + self::$defaultClonerOptions;
|
||||
$this->cloner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of non-default HtmlDumper configuration options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDumperOptions()
|
||||
{
|
||||
if ($this->dumperOptions === null) {
|
||||
$this->dumperOptions = self::$defaultDumperOptions;
|
||||
}
|
||||
return $this->dumperOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges an array of non-default HtmlDumper configuration options with the existing non-default
|
||||
* options.
|
||||
*
|
||||
* Configuration options are:
|
||||
* - styles: a map of CSS styles to include in the assets, as documented in
|
||||
* HtmlDumper::setStyles.
|
||||
* - expanded_depth: the tree depth to initially expand.
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
* - max_string: maximum string size.
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
* - file_link_format: link format for files; %f expanded to file and %l expanded to line
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function mergeDumperOptions($options)
|
||||
{
|
||||
$this->dumperOptions = $options + $this->getDumperOptions();
|
||||
$this->dumper = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the array of non-default HtmlDumper configuration options without retaining any of the
|
||||
* existing non-default options.
|
||||
*
|
||||
* Configuration options are:
|
||||
* - styles: a map of CSS styles to include in the assets, as documented in
|
||||
* HtmlDumper::setStyles.
|
||||
* - expanded_depth: the tree depth to initially expand.
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
* - max_string: maximum string size.
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
* - file_link_format: link format for files; %f expanded to file and %l expanded to line
|
||||
* (Requires Symfony 3.2; ignored on older versions.)
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function resetDumperOptions($options = null)
|
||||
{
|
||||
$this->dumperOptions = ($options ?: array()) + self::$defaultDumperOptions;
|
||||
$this->dumper = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the data from a variable and serializes it for later rendering.
|
||||
*
|
||||
* @param mixed $data The variable to capture.
|
||||
* @return string Serialized variable data.
|
||||
*/
|
||||
public function captureVar($data)
|
||||
{
|
||||
return serialize($this->getCloner()->cloneVar($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display options for the HTML dumper.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDisplayOptions()
|
||||
{
|
||||
$displayOptions = array();
|
||||
$dumperOptions = $this->getDumperOptions();
|
||||
// Only used by Symfony 3.2 and newer:
|
||||
if (isset($dumperOptions['expanded_depth'])) {
|
||||
$displayOptions['maxDepth'] = $dumperOptions['expanded_depth'];
|
||||
}
|
||||
// Only used by Symfony 3.2 and newer:
|
||||
if (isset($dumperOptions['max_string'])) {
|
||||
$displayOptions['maxStringLength'] = $dumperOptions['max_string'];
|
||||
}
|
||||
// Only used by Symfony 3.2 and newer:
|
||||
if (isset($dumperOptions['file_link_format'])) {
|
||||
$displayOptions['fileLinkFormat'] = $dumperOptions['file_link_format'];
|
||||
}
|
||||
return $displayOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders previously-captured data from captureVar to HTML and returns it as a string.
|
||||
*
|
||||
* @param string $capturedData Captured data from captureVar.
|
||||
* @param array $seekPath Pass an array of keys to traverse if you only want to render a subset
|
||||
* of the data.
|
||||
* @return string HTML rendering of the variable.
|
||||
*/
|
||||
public function renderCapturedVar($capturedData, $seekPath = array())
|
||||
{
|
||||
$data = unserialize($capturedData);
|
||||
if (!method_exists($data, 'seek')) {
|
||||
$data = new SeekingData($data->getRawData());
|
||||
}
|
||||
|
||||
foreach ($seekPath as $key) {
|
||||
$data = $data->seek($key);
|
||||
}
|
||||
|
||||
return $this->dump($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures and renders the data from a variable to HTML and returns it as a string.
|
||||
*
|
||||
* @param mixed $data The variable to capture and render.
|
||||
* @return string HTML rendering of the variable.
|
||||
*/
|
||||
public function renderVar($data)
|
||||
{
|
||||
return $this->dump($this->getCloner()->cloneVar($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns assets required for rendering variables.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAssets() {
|
||||
$dumper = $this->getDumper();
|
||||
$dumper->resetDumpHeader(); // this will cause the default dump header to regenerate
|
||||
return array(
|
||||
'inline_head' => array(
|
||||
'html_var_dumper' => $dumper->getDumpHeaderByDebugBar(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to dump a Data object to HTML.
|
||||
*
|
||||
* @param Data $data
|
||||
* @return string
|
||||
*/
|
||||
protected function dump(Data $data)
|
||||
{
|
||||
$dumper = $this->getDumper();
|
||||
$output = fopen('php://memory', 'r+b');
|
||||
$dumper->setOutput($output);
|
||||
$dumper->setDumpHeader(''); // we don't actually want a dump header
|
||||
// NOTE: Symfony 3.2 added the third $extraDisplayOptions parameter. Older versions will
|
||||
// safely ignore it.
|
||||
$dumper->dump($data, null, $this->getDisplayOptions());
|
||||
$result = stream_get_contents($output, -1, 0);
|
||||
fclose($output);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\DataFormatter;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
|
||||
trait HasDataFormatter
|
||||
{
|
||||
// The HTML var dumper requires debug bar users to support the new inline assets, which not all
|
||||
// may support yet - so return false by default for now.
|
||||
protected $useHtmlVarDumper = false;
|
||||
protected $dataFormater;
|
||||
protected $varDumper;
|
||||
|
||||
/**
|
||||
* Sets a flag indicating whether the Symfony HtmlDumper will be used to dump variables for
|
||||
* rich variable rendering.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function useHtmlVarDumper($value = true)
|
||||
{
|
||||
$this->useHtmlVarDumper = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable
|
||||
* rendering.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isHtmlVarDumperUsed()
|
||||
{
|
||||
return $this->useHtmlVarDumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default data formater instance used by all collectors subclassing this class
|
||||
*
|
||||
* @param DataFormatterInterface $formater
|
||||
*/
|
||||
public static function setDefaultDataFormatter(DataFormatterInterface $formater)
|
||||
{
|
||||
DataCollector::$defaultDataFormatter = $formater;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default data formater
|
||||
*
|
||||
* @return DataFormatterInterface
|
||||
*/
|
||||
public static function getDefaultDataFormatter()
|
||||
{
|
||||
if (DataCollector::$defaultDataFormatter === null) {
|
||||
DataCollector::$defaultDataFormatter = new DataFormatter();
|
||||
}
|
||||
return DataCollector::$defaultDataFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data formater instance used by this collector
|
||||
*
|
||||
* @param DataFormatterInterface $formater
|
||||
* @return $this
|
||||
*/
|
||||
public function setDataFormatter(DataFormatterInterface $formater)
|
||||
{
|
||||
$this->dataFormater = $formater;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DataFormatterInterface
|
||||
*/
|
||||
public function getDataFormatter()
|
||||
{
|
||||
if ($this->dataFormater === null) {
|
||||
$this->dataFormater = DataCollector::getDefaultDataFormatter();
|
||||
}
|
||||
return $this->dataFormater;
|
||||
}
|
||||
/**
|
||||
* Sets the default variable dumper used by all collectors subclassing this class
|
||||
*
|
||||
* @param DebugBarVarDumper $varDumper
|
||||
*/
|
||||
public static function setDefaultVarDumper(DebugBarVarDumper $varDumper)
|
||||
{
|
||||
DataCollector::$defaultVarDumper = $varDumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default variable dumper
|
||||
*
|
||||
* @return DebugBarVarDumper
|
||||
*/
|
||||
public static function getDefaultVarDumper()
|
||||
{
|
||||
if (DataCollector::$defaultVarDumper === null) {
|
||||
DataCollector::$defaultVarDumper = new DebugBarVarDumper();
|
||||
}
|
||||
return DataCollector::$defaultVarDumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the variable dumper instance used by this collector
|
||||
*
|
||||
* @param DebugBarVarDumper $varDumper
|
||||
* @return $this
|
||||
*/
|
||||
public function setVarDumper(DebugBarVarDumper $varDumper)
|
||||
{
|
||||
$this->varDumper = $varDumper;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variable dumper instance used by this collector; note that collectors using this
|
||||
* instance need to be sure to return the static assets provided by the variable dumper.
|
||||
*
|
||||
* @return DebugBarVarDumper
|
||||
*/
|
||||
public function getVarDumper()
|
||||
{
|
||||
if ($this->varDumper === null) {
|
||||
$this->varDumper = DataCollector::getDefaultVarDumper();
|
||||
}
|
||||
return $this->varDumper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function formatVar($var)
|
||||
{
|
||||
return $this->getDataFormatter()->formatVar($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function formatDuration($seconds)
|
||||
{
|
||||
return $this->getDataFormatter()->formatDuration($seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function formatBytes($size, $precision = 2)
|
||||
{
|
||||
return $this->getDataFormatter()->formatBytes($size, $precision);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\DataFormatter;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
|
||||
trait HasXdebugLinks
|
||||
{
|
||||
protected $xdebugLinkTemplate = '';
|
||||
protected $xdebugShouldUseAjax = false;
|
||||
protected $xdebugReplacements = array();
|
||||
|
||||
/**
|
||||
* Shorten the file path by removing the xdebug path replacements
|
||||
*
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
public function normalizeFilePath($file)
|
||||
{
|
||||
if (empty($file)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (@file_exists($file)) {
|
||||
$file = realpath($file);
|
||||
}
|
||||
|
||||
foreach (array_keys($this->xdebugReplacements) as $path) {
|
||||
if (strpos($file, $path) === 0) {
|
||||
$file = substr($file, strlen($path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ltrim(str_replace('\\', '/', $file), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an Xdebug Link to a file
|
||||
*
|
||||
* @param string $file
|
||||
* @param int|null $line
|
||||
*
|
||||
* @return array {
|
||||
* @var string $url
|
||||
* @var bool $ajax should be used to open the url instead of a normal links
|
||||
* }
|
||||
*/
|
||||
public function getXdebugLink($file, $line = null)
|
||||
{
|
||||
if (empty($file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (@file_exists($file)) {
|
||||
$file = realpath($file);
|
||||
}
|
||||
|
||||
foreach ($this->xdebugReplacements as $path => $replacement) {
|
||||
if (strpos($file, $path) === 0) {
|
||||
$file = $replacement . substr($file, strlen($path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$url = strtr($this->getXdebugLinkTemplate(), [
|
||||
'%f' => rawurlencode(str_replace('\\', '/', $file)),
|
||||
'%l' => rawurlencode((string) $line ?: 1),
|
||||
]);
|
||||
if ($url) {
|
||||
return [
|
||||
'url' => $url,
|
||||
'ajax' => $this->getXdebugShouldUseAjax(),
|
||||
'filename' => basename($file),
|
||||
'line' => (string) $line ?: '?'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getXdebugLinkTemplate()
|
||||
{
|
||||
if (empty($this->xdebugLinkTemplate) && !empty(ini_get('xdebug.file_link_format'))) {
|
||||
$this->xdebugLinkTemplate = ini_get('xdebug.file_link_format');
|
||||
}
|
||||
|
||||
return $this->xdebugLinkTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $editor
|
||||
*/
|
||||
public function setEditorLinkTemplate($editor)
|
||||
{
|
||||
$editorLinkTemplates = array(
|
||||
'sublime' => 'subl://open?url=file://%f&line=%l',
|
||||
'textmate' => 'txmt://open?url=file://%f&line=%l',
|
||||
'emacs' => 'emacs://open?url=file://%f&line=%l',
|
||||
'macvim' => 'mvim://open/?url=file://%f&line=%l',
|
||||
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
|
||||
'phpstorm-remote' => 'javascript:(()=>{let r=new XMLHttpRequest;' .
|
||||
'r.open(\'get\',\'http://localhost:63342/api/file/%f:%l\');r.send();})()',
|
||||
'idea' => 'idea://open?file=%f&line=%l',
|
||||
'idea-remote' => 'javascript:(()=>{let r=new XMLHttpRequest;' .
|
||||
'r.open(\'get\',\'http://localhost:63342/api/file/?file=%f&line=%l\');r.send();})()',
|
||||
'vscode' => 'vscode://file/%f:%l',
|
||||
'vscode-insiders' => 'vscode-insiders://file/%f:%l',
|
||||
'vscode-remote' => 'vscode://vscode-remote/%f:%l',
|
||||
'vscode-insiders-remote' => 'vscode-insiders://vscode-remote/%f:%l',
|
||||
'vscodium' => 'vscodium://file/%f:%l',
|
||||
'nova' => 'nova://core/open/file?filename=%f&line=%l',
|
||||
'xdebug' => 'xdebug://%f@%l',
|
||||
'atom' => 'atom://core/open/file?filename=%f&line=%l',
|
||||
'espresso' => 'x-espresso://open?filepath=%f&lines=%l',
|
||||
'netbeans' => 'netbeans://open/?f=%f:%l',
|
||||
);
|
||||
|
||||
if (is_string($editor) && isset($editorLinkTemplates[$editor])) {
|
||||
$this->setXdebugLinkTemplate($editorLinkTemplates[$editor]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xdebugLinkTemplate
|
||||
* @param bool $shouldUseAjax
|
||||
*/
|
||||
public function setXdebugLinkTemplate($xdebugLinkTemplate, $shouldUseAjax = false)
|
||||
{
|
||||
if ($xdebugLinkTemplate === 'idea') {
|
||||
$this->xdebugLinkTemplate = 'http://localhost:63342/api/file/?file=%f&line=%l';
|
||||
$this->xdebugShouldUseAjax = true;
|
||||
} else {
|
||||
$this->xdebugLinkTemplate = $xdebugLinkTemplate;
|
||||
$this->xdebugShouldUseAjax = $shouldUseAjax;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getXdebugShouldUseAjax()
|
||||
{
|
||||
return $this->xdebugShouldUseAjax;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array of filename-replacements
|
||||
*
|
||||
* this is useful f.e. when using vagrant or remote servers,
|
||||
* where the path of the file is different between server and
|
||||
* development environment
|
||||
*
|
||||
* @return array key-value-pairs of replacements, key = path on server, value = replacement
|
||||
*/
|
||||
public function getXdebugReplacements()
|
||||
{
|
||||
return $this->xdebugReplacements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $xdebugReplacements
|
||||
*/
|
||||
public function addXdebugReplacements($xdebugReplacements)
|
||||
{
|
||||
foreach ($xdebugReplacements as $serverPath => $replacement) {
|
||||
$this->setXdebugReplacement($serverPath, $replacement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $xdebugReplacements
|
||||
*/
|
||||
public function setXdebugReplacements($xdebugReplacements)
|
||||
{
|
||||
$this->xdebugReplacements = $xdebugReplacements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serverPath
|
||||
* @param string $replacement
|
||||
*/
|
||||
public function setXdebugReplacement($serverPath, $replacement)
|
||||
{
|
||||
$this->xdebugReplacements[$serverPath] = $replacement;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\DataFormatter\VarDumper;
|
||||
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
|
||||
/**
|
||||
* We have to extend the base HtmlDumper class in order to get access to the protected-only
|
||||
* getDumpHeader function.
|
||||
*/
|
||||
class DebugBarHtmlDumper extends HtmlDumper
|
||||
{
|
||||
/**
|
||||
* Resets an HTML header.
|
||||
*/
|
||||
public function resetDumpHeader()
|
||||
{
|
||||
$this->dumpHeader = null;
|
||||
}
|
||||
|
||||
public function getDumpHeaderByDebugBar() {
|
||||
// getDumpHeader is protected:
|
||||
return str_replace('pre.sf-dump', '.phpdebugbar pre.sf-dump', $this->getDumpHeader());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user