first commit
This commit is contained in:
96
vendor/barryvdh/laravel-debugbar/src/DataCollector/CacheCollector.php
vendored
Normal file
96
vendor/barryvdh/laravel-debugbar/src/DataCollector/CacheCollector.php
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use Illuminate\Cache\Events\CacheEvent;
|
||||
use Illuminate\Cache\Events\CacheHit;
|
||||
use Illuminate\Cache\Events\CacheMissed;
|
||||
use Illuminate\Cache\Events\KeyForgotten;
|
||||
use Illuminate\Cache\Events\KeyWritten;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class CacheCollector extends TimeDataCollector
|
||||
{
|
||||
/** @var bool */
|
||||
protected $collectValues;
|
||||
|
||||
/** @var array */
|
||||
protected $classMap = [
|
||||
CacheHit::class => 'hit',
|
||||
CacheMissed::class => 'missed',
|
||||
KeyWritten::class => 'written',
|
||||
KeyForgotten::class => 'forgotten',
|
||||
];
|
||||
|
||||
public function __construct($requestStartTime, $collectValues)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->collectValues = $collectValues;
|
||||
}
|
||||
|
||||
public function onCacheEvent(CacheEvent $event)
|
||||
{
|
||||
$class = get_class($event);
|
||||
$params = get_object_vars($event);
|
||||
|
||||
$label = $this->classMap[$class];
|
||||
|
||||
if (isset($params['value'])) {
|
||||
if ($this->collectValues) {
|
||||
$params['value'] = htmlspecialchars($this->getDataFormatter()->formatVar($event->value));
|
||||
} else {
|
||||
unset($params['value']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($params['key']) && in_array($label, ['hit', 'written'])) {
|
||||
$params['delete'] = route('debugbar.cache.delete', [
|
||||
'key' => urlencode($params['key']),
|
||||
'tags' => !empty($params['tags']) ? json_encode($params['tags']) : '',
|
||||
]);
|
||||
}
|
||||
|
||||
$time = microtime(true);
|
||||
$this->addMeasure($label . "\t" . $event->key, $time, $time, $params);
|
||||
}
|
||||
|
||||
|
||||
public function subscribe(Dispatcher $dispatcher)
|
||||
{
|
||||
foreach ($this->classMap as $eventClass => $type) {
|
||||
$dispatcher->listen($eventClass, [$this, 'onCacheEvent']);
|
||||
}
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
$data = parent::collect();
|
||||
$data['nb_measures'] = count($data['measures']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'cache';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
'cache' => [
|
||||
'icon' => 'clipboard',
|
||||
'widget' => 'PhpDebugBar.Widgets.LaravelCacheWidget',
|
||||
'map' => 'cache',
|
||||
'default' => '{}',
|
||||
],
|
||||
'cache:badge' => [
|
||||
'map' => 'cache.nb_measures',
|
||||
'default' => 'null',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
128
vendor/barryvdh/laravel-debugbar/src/DataCollector/EventCollector.php
vendored
Normal file
128
vendor/barryvdh/laravel-debugbar/src/DataCollector/EventCollector.php
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use Barryvdh\Debugbar\DataFormatter\SimpleFormatter;
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
class EventCollector extends TimeDataCollector
|
||||
{
|
||||
/** @var Dispatcher */
|
||||
protected $events;
|
||||
|
||||
/** @var integer */
|
||||
protected $previousTime;
|
||||
|
||||
/** @var bool */
|
||||
protected $collectValues;
|
||||
|
||||
public function __construct($requestStartTime = null, $collectValues = false)
|
||||
{
|
||||
parent::__construct($requestStartTime);
|
||||
$this->previousTime = microtime(true);
|
||||
$this->collectValues = $collectValues;
|
||||
$this->setDataFormatter(new SimpleFormatter());
|
||||
}
|
||||
|
||||
public function onWildcardEvent($name = null, $data = [])
|
||||
{
|
||||
$currentTime = microtime(true);
|
||||
|
||||
if (! $this->collectValues) {
|
||||
$this->addMeasure($name, $this->previousTime, $currentTime);
|
||||
$this->previousTime = $currentTime;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$params = $this->prepareParams($data);
|
||||
|
||||
// Find all listeners for the current event
|
||||
foreach ($this->events->getListeners($name) as $i => $listener) {
|
||||
// Check if it's an object + method name
|
||||
if (is_array($listener) && count($listener) > 1 && is_object($listener[0])) {
|
||||
list($class, $method) = $listener;
|
||||
|
||||
// Skip this class itself
|
||||
if ($class instanceof static) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Format the listener to readable format
|
||||
$listener = get_class($class) . '@' . $method;
|
||||
|
||||
// Handle closures
|
||||
} elseif ($listener instanceof \Closure) {
|
||||
$reflector = new \ReflectionFunction($listener);
|
||||
|
||||
// Skip our own listeners
|
||||
if ($reflector->getNamespaceName() == 'Barryvdh\Debugbar') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Format the closure to a readable format
|
||||
$filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
|
||||
$lines = $reflector->getStartLine() . '-' . $reflector->getEndLine();
|
||||
$listener = $reflector->getName() . ' (' . $filename . ':' . $lines . ')';
|
||||
} else {
|
||||
// Not sure if this is possible, but to prevent edge cases
|
||||
$listener = $this->getDataFormatter()->formatVar($listener);
|
||||
}
|
||||
|
||||
$params['listeners.' . $i] = $listener;
|
||||
}
|
||||
$this->addMeasure($name, $this->previousTime, $currentTime, $params);
|
||||
$this->previousTime = $currentTime;
|
||||
}
|
||||
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$this->events = $events;
|
||||
$events->listen('*', [$this, 'onWildcardEvent']);
|
||||
}
|
||||
|
||||
protected function prepareParams($params)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($params as $key => $value) {
|
||||
if (is_object($value) && Str::is('Illuminate\*\Events\*', get_class($value))) {
|
||||
$value = $this->prepareParams(get_object_vars($value));
|
||||
}
|
||||
$data[$key] = htmlentities($this->getDataFormatter()->formatVar($value), ENT_QUOTES, 'UTF-8', false);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
$data = parent::collect();
|
||||
$data['nb_measures'] = count($data['measures']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'event';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"events" => [
|
||||
"icon" => "tasks",
|
||||
"widget" => "PhpDebugBar.Widgets.TimelineWidget",
|
||||
"map" => "event",
|
||||
"default" => "{}",
|
||||
],
|
||||
'events:badge' => [
|
||||
'map' => 'event.nb_measures',
|
||||
'default' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
136
vendor/barryvdh/laravel-debugbar/src/DataCollector/FilesCollector.php
vendored
Normal file
136
vendor/barryvdh/laravel-debugbar/src/DataCollector/FilesCollector.php
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
class FilesCollector extends DataCollector implements Renderable
|
||||
{
|
||||
/** @var \Illuminate\Container\Container */
|
||||
protected $app;
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Container\Container $app
|
||||
*/
|
||||
public function __construct(Container $app = null)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->basePath = base_path();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$files = $this->getIncludedFiles();
|
||||
$compiled = $this->getCompiledFiles();
|
||||
|
||||
$included = [];
|
||||
$alreadyCompiled = [];
|
||||
foreach ($files as $file) {
|
||||
// Skip the files from Debugbar, they are only loaded for Debugging and confuse the output.
|
||||
// Of course some files are stil always loaded (ServiceProvider, Facade etc)
|
||||
if (
|
||||
strpos($file, 'vendor/maximebf/debugbar/src') !== false || strpos(
|
||||
$file,
|
||||
'vendor/barryvdh/laravel-debugbar/src'
|
||||
) !== false
|
||||
) {
|
||||
continue;
|
||||
} elseif (!in_array($file, $compiled)) {
|
||||
$included[] = [
|
||||
'message' => "'" . $this->stripBasePath($file) . "',",
|
||||
// Use PHP syntax so we can copy-paste to compile config file.
|
||||
'is_string' => true,
|
||||
];
|
||||
} else {
|
||||
$alreadyCompiled[] = [
|
||||
'message' => "* '" . $this->stripBasePath($file) . "',",
|
||||
// Mark with *, so know they are compiled anyway.
|
||||
'is_string' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// First the included files, then those that are going to be compiled.
|
||||
$messages = array_merge($included, $alreadyCompiled);
|
||||
|
||||
return [
|
||||
'messages' => $messages,
|
||||
'count' => count($included),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the files included on load.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncludedFiles()
|
||||
{
|
||||
return get_included_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the files that are going to be compiled, so they aren't as important.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCompiledFiles()
|
||||
{
|
||||
if ($this->app && class_exists('Illuminate\Foundation\Console\OptimizeCommand')) {
|
||||
$reflector = new \ReflectionClass('Illuminate\Foundation\Console\OptimizeCommand');
|
||||
$path = dirname($reflector->getFileName()) . '/Optimize/config.php';
|
||||
|
||||
if (file_exists($path)) {
|
||||
$app = $this->app;
|
||||
$core = require $path;
|
||||
return array_merge($core, $app['config']['compile']);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the basePath from the paths, so they are relative to the base
|
||||
*
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
protected function stripBasePath($path)
|
||||
{
|
||||
return ltrim(str_replace($this->basePath, '', $path), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
$name = $this->getName();
|
||||
return [
|
||||
"$name" => [
|
||||
"icon" => "files-o",
|
||||
"widget" => "PhpDebugBar.Widgets.MessagesWidget",
|
||||
"map" => "$name.messages",
|
||||
"default" => "{}"
|
||||
],
|
||||
"$name:badge" => [
|
||||
"map" => "$name.count",
|
||||
"default" => "null"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'files';
|
||||
}
|
||||
}
|
66
vendor/barryvdh/laravel-debugbar/src/DataCollector/GateCollector.php
vendored
Normal file
66
vendor/barryvdh/laravel-debugbar/src/DataCollector/GateCollector.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use Barryvdh\Debugbar\DataFormatter\SimpleFormatter;
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Contracts\Auth\Access\Gate;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Collector for Laravel's Auth provider
|
||||
*/
|
||||
class GateCollector extends MessagesCollector
|
||||
{
|
||||
/**
|
||||
* @param Gate $gate
|
||||
*/
|
||||
public function __construct(Gate $gate)
|
||||
{
|
||||
parent::__construct('gate');
|
||||
$this->setDataFormatter(new SimpleFormatter());
|
||||
$gate->after(function ($user, $ability, $result, $arguments = []) {
|
||||
$this->addCheck($user, $ability, $result, $arguments);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function customizeMessageHtml($messageHtml, $message)
|
||||
{
|
||||
$pos = strpos((string) $messageHtml, 'array:4');
|
||||
if ($pos !== false) {
|
||||
$messageHtml = substr_replace($messageHtml, $message['ability'], $pos, 7);
|
||||
}
|
||||
|
||||
return parent::customizeMessageHtml($messageHtml, $message);
|
||||
}
|
||||
|
||||
public function addCheck($user, $ability, $result, $arguments = [])
|
||||
{
|
||||
$userKey = 'user';
|
||||
$userId = null;
|
||||
|
||||
if ($user) {
|
||||
$userKey = Str::snake(class_basename($user));
|
||||
$userId = $user instanceof Authenticatable ? $user->getAuthIdentifier() : $user->getKey();
|
||||
}
|
||||
|
||||
$label = $result ? 'success' : 'error';
|
||||
|
||||
if ($result instanceof Response) {
|
||||
$label = $result->allowed() ? 'success' : 'error';
|
||||
}
|
||||
|
||||
$this->addMessage([
|
||||
'ability' => $ability,
|
||||
'result' => $result,
|
||||
$userKey => $userId,
|
||||
'arguments' => $this->getDataFormatter()->formatVar($arguments),
|
||||
], $label, false);
|
||||
}
|
||||
}
|
63
vendor/barryvdh/laravel-debugbar/src/DataCollector/JobsCollector.php
vendored
Normal file
63
vendor/barryvdh/laravel-debugbar/src/DataCollector/JobsCollector.php
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
|
||||
*/
|
||||
class JobsCollector extends DataCollector implements DataCollectorInterface, Renderable
|
||||
{
|
||||
public $jobs = [];
|
||||
public $count = 0;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(Dispatcher $events)
|
||||
{
|
||||
$events->listen(\Illuminate\Queue\Events\JobQueued::class, function ($event) {
|
||||
$class = get_class($event->job);
|
||||
$this->jobs[$class] = ($this->jobs[$class] ?? 0) + 1;
|
||||
$this->count++;
|
||||
});
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
ksort($this->jobs, SORT_NUMERIC);
|
||||
|
||||
return ['data' => array_reverse($this->jobs), 'count' => $this->count];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'jobs';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"jobs" => [
|
||||
"icon" => "briefcase",
|
||||
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
|
||||
"map" => "jobs.data",
|
||||
"default" => "{}"
|
||||
],
|
||||
'jobs:badge' => [
|
||||
'map' => 'jobs.count',
|
||||
'default' => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
71
vendor/barryvdh/laravel-debugbar/src/DataCollector/LaravelCollector.php
vendored
Normal file
71
vendor/barryvdh/laravel-debugbar/src/DataCollector/LaravelCollector.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class LaravelCollector extends DataCollector implements Renderable
|
||||
{
|
||||
/** @var \Illuminate\Foundation\Application $app */
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
*/
|
||||
public function __construct(Application $app = null)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
// Fallback if not injected
|
||||
$app = $this->app ?: app();
|
||||
|
||||
return [
|
||||
"version" => $app::VERSION,
|
||||
"environment" => $app->environment(),
|
||||
"locale" => $app->getLocale(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'laravel';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"version" => [
|
||||
"icon" => "github",
|
||||
"tooltip" => "Laravel Version",
|
||||
"map" => "laravel.version",
|
||||
"default" => ""
|
||||
],
|
||||
"environment" => [
|
||||
"icon" => "desktop",
|
||||
"tooltip" => "Environment",
|
||||
"map" => "laravel.environment",
|
||||
"default" => ""
|
||||
],
|
||||
"locale" => [
|
||||
"icon" => "flag",
|
||||
"tooltip" => "Current locale",
|
||||
"map" => "laravel.locale",
|
||||
"default" => "",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
103
vendor/barryvdh/laravel-debugbar/src/DataCollector/LivewireCollector.php
vendored
Normal file
103
vendor/barryvdh/laravel-debugbar/src/DataCollector/LivewireCollector.php
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Livewire;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Collector for Models.
|
||||
*/
|
||||
class LivewireCollector extends DataCollector implements DataCollectorInterface, Renderable
|
||||
{
|
||||
public $data = [];
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
// Listen to Livewire views
|
||||
Livewire::listen('view:render', function (View $view) use ($request) {
|
||||
/** @var \Livewire\Component $component */
|
||||
$component = $view->getData()['_instance'];
|
||||
|
||||
// Create a unique name for each component
|
||||
$key = $component->getName() . ' #' . $component->id;
|
||||
|
||||
$data = [
|
||||
'data' => $component->getPublicPropertiesDefinedBySubClass(),
|
||||
];
|
||||
|
||||
if ($request->request->get('id') == $component->id) {
|
||||
$data['oldData'] = $request->request->get('data');
|
||||
$data['actionQueue'] = $request->request->get('actionQueue');
|
||||
}
|
||||
|
||||
$data['name'] = $component->getName();
|
||||
$data['view'] = $view->name();
|
||||
$data['component'] = get_class($component);
|
||||
$data['id'] = $component->id;
|
||||
|
||||
$this->data[$key] = $this->formatVar($data);
|
||||
});
|
||||
|
||||
Livewire::listen('render', function (Component $component) use ($request) {
|
||||
// Create an unique name for each compoent
|
||||
$key = $component->getName() . ' #' . $component->getId();
|
||||
|
||||
$data = [
|
||||
'data' => $component->all(),
|
||||
];
|
||||
|
||||
if ($request->request->get('id') == $component->getId()) {
|
||||
$data['oldData'] = $request->request->get('data');
|
||||
$data['actionQueue'] = $request->request->get('actionQueue');
|
||||
}
|
||||
|
||||
$data['name'] = $component->getName();
|
||||
$data['component'] = get_class($component);
|
||||
$data['id'] = $component->getId();
|
||||
|
||||
$this->data[$key] = $this->formatVar($data);
|
||||
});
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
return ['data' => $this->data, 'count' => count($this->data)];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'livewire';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"livewire" => [
|
||||
"icon" => "bolt",
|
||||
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
|
||||
"map" => "livewire.data",
|
||||
"default" => "{}"
|
||||
],
|
||||
'livewire:badge' => [
|
||||
'map' => 'livewire.count',
|
||||
'default' => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
145
vendor/barryvdh/laravel-debugbar/src/DataCollector/LogsCollector.php
vendored
Normal file
145
vendor/barryvdh/laravel-debugbar/src/DataCollector/LogsCollector.php
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use Illuminate\Support\Arr;
|
||||
use Psr\Log\LogLevel;
|
||||
use ReflectionClass;
|
||||
|
||||
class LogsCollector extends MessagesCollector
|
||||
{
|
||||
protected $lines = 124;
|
||||
|
||||
public function __construct($path = null, $name = 'logs')
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$paths = Arr::wrap($path ?: [
|
||||
storage_path('logs/laravel.log'),
|
||||
storage_path('logs/laravel-' . date('Y-m-d') . '.log'), // for daily driver
|
||||
]);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$this->getStorageLogs($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get logs apache in app/storage/logs
|
||||
* only 24 last of current day
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStorageLogs($path)
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Load the latest lines, guessing about 15x the number of log entries (for stack traces etc)
|
||||
$file = implode("", $this->tailFile($path, $this->lines));
|
||||
$basename = basename($path);
|
||||
|
||||
foreach ($this->getLogs($file) as $log) {
|
||||
$this->messages[] = [
|
||||
'message' => $log['header'] . $log['stack'],
|
||||
'label' => $log['level'],
|
||||
'time' => substr($log['header'], 1, 19),
|
||||
'collector' => $basename,
|
||||
'is_string' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By Ain Tohvri (ain)
|
||||
* http://tekkie.flashbit.net/php/tail-functionality-in-php
|
||||
* @param string $file
|
||||
* @param int $lines
|
||||
* @return array
|
||||
*/
|
||||
protected function tailFile($file, $lines)
|
||||
{
|
||||
$handle = fopen($file, "r");
|
||||
$linecounter = $lines;
|
||||
$pos = -2;
|
||||
$beginning = false;
|
||||
$text = [];
|
||||
while ($linecounter > 0) {
|
||||
$t = " ";
|
||||
while ($t != "\n") {
|
||||
if (fseek($handle, $pos, SEEK_END) == -1) {
|
||||
$beginning = true;
|
||||
break;
|
||||
}
|
||||
$t = fgetc($handle);
|
||||
$pos--;
|
||||
}
|
||||
$linecounter--;
|
||||
if ($beginning) {
|
||||
rewind($handle);
|
||||
}
|
||||
$text[$lines - $linecounter - 1] = fgets($handle);
|
||||
if ($beginning) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
return array_reverse($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a string for log entries
|
||||
* Based on https://github.com/mikemand/logviewer/blob/master/src/Kmd/Logviewer/Logviewer.php by mikemand
|
||||
*
|
||||
* @param $file
|
||||
* @return array
|
||||
*/
|
||||
public function getLogs($file)
|
||||
{
|
||||
$pattern = "/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/";
|
||||
|
||||
$log_levels = $this->getLevels();
|
||||
|
||||
// There has GOT to be a better way of doing this...
|
||||
preg_match_all($pattern, $file, $headings);
|
||||
$log_data = preg_split($pattern, $file);
|
||||
|
||||
$log = [];
|
||||
foreach ($headings as $h) {
|
||||
for ($i = 0, $j = count($h); $i < $j; $i++) {
|
||||
foreach ($log_levels as $ll) {
|
||||
if (strpos(strtolower($h[$i]), strtolower('.' . $ll))) {
|
||||
$log[] = ['level' => $ll, 'header' => $h[$i], 'stack' => $log_data[$i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return array_reverse(parent::getMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log levels from psr/log.
|
||||
* Based on https://github.com/mikemand/logviewer/blob/master/src/Kmd/Logviewer/Logviewer.php by mikemand
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getLevels()
|
||||
{
|
||||
$class = new ReflectionClass(new LogLevel());
|
||||
return $class->getConstants();
|
||||
}
|
||||
}
|
66
vendor/barryvdh/laravel-debugbar/src/DataCollector/ModelsCollector.php
vendored
Normal file
66
vendor/barryvdh/laravel-debugbar/src/DataCollector/ModelsCollector.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* Collector for Models.
|
||||
* @deprecated in favor of \DebugBar\DataCollector\ObjectCountCollector
|
||||
*/
|
||||
class ModelsCollector extends DataCollector implements DataCollectorInterface, Renderable
|
||||
{
|
||||
public $models = [];
|
||||
public $count = 0;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(Dispatcher $events)
|
||||
{
|
||||
$events->listen('eloquent.retrieved:*', function ($event, $models) {
|
||||
foreach (array_filter($models) as $model) {
|
||||
$class = get_class($model);
|
||||
$this->models[$class] = ($this->models[$class] ?? 0) + 1;
|
||||
$this->count++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
ksort($this->models, SORT_NUMERIC);
|
||||
|
||||
return ['data' => array_reverse($this->models), 'count' => $this->count];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'models';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"models" => [
|
||||
"icon" => "cubes",
|
||||
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
|
||||
"map" => "models.data",
|
||||
"default" => "{}"
|
||||
],
|
||||
'models:badge' => [
|
||||
'map' => 'models.count',
|
||||
'default' => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
182
vendor/barryvdh/laravel-debugbar/src/DataCollector/MultiAuthCollector.php
vendored
Normal file
182
vendor/barryvdh/laravel-debugbar/src/DataCollector/MultiAuthCollector.php
vendored
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Auth\Recaller;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Collector for Laravel's Auth provider
|
||||
*/
|
||||
class MultiAuthCollector extends DataCollector implements Renderable
|
||||
{
|
||||
/** @var array $guards */
|
||||
protected $guards;
|
||||
|
||||
/** @var \Illuminate\Auth\AuthManager */
|
||||
protected $auth;
|
||||
|
||||
/** @var bool */
|
||||
protected $showName = false;
|
||||
|
||||
/** @var bool */
|
||||
protected $showGuardsData = true;
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Auth\AuthManager $auth
|
||||
* @param array $guards
|
||||
*/
|
||||
public function __construct($auth, $guards)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->guards = $guards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to show the users name/email
|
||||
* @param bool $showName
|
||||
*/
|
||||
public function setShowName($showName)
|
||||
{
|
||||
$this->showName = (bool) $showName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to hide the guards tab, and show only name
|
||||
* @param bool $showGuardsData
|
||||
*/
|
||||
public function setShowGuardsData($showGuardsData)
|
||||
{
|
||||
$this->showGuardsData = (bool) $showGuardsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritDoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$data = [
|
||||
'guards' => [],
|
||||
];
|
||||
$names = '';
|
||||
|
||||
foreach ($this->guards as $guardName => $config) {
|
||||
try {
|
||||
$guard = $this->auth->guard($guardName);
|
||||
if ($this->hasUser($guard)) {
|
||||
$user = $guard->user();
|
||||
|
||||
if (!is_null($user)) {
|
||||
$data['guards'][$guardName] = $this->getUserInformation($user);
|
||||
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
|
||||
}
|
||||
} else {
|
||||
$data['guards'][$guardName] = null;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['guards'] as $key => $var) {
|
||||
if (!is_string($data['guards'][$key])) {
|
||||
$data['guards'][$key] = $this->formatVar($var);
|
||||
}
|
||||
}
|
||||
|
||||
$data['names'] = rtrim($names, ', ');
|
||||
if (!$this->showGuardsData) {
|
||||
unset($data['guards']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function hasUser(Guard $guard)
|
||||
{
|
||||
if (method_exists($guard, 'hasUser')) {
|
||||
return $guard->hasUser();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get displayed user information
|
||||
* @param \Illuminate\Auth\UserInterface $user
|
||||
* @return array
|
||||
*/
|
||||
protected function getUserInformation($user = null)
|
||||
{
|
||||
// Defaults
|
||||
if (is_null($user)) {
|
||||
return [
|
||||
'name' => 'Guest',
|
||||
'user' => ['guest' => true],
|
||||
];
|
||||
}
|
||||
|
||||
// The default auth identifer is the ID number, which isn't all that
|
||||
// useful. Try username, email and name.
|
||||
$identifier = $user instanceof Authenticatable ? $user->getAuthIdentifier() : $user->getKey();
|
||||
if (is_numeric($identifier) || Str::isUuid($identifier) || Str::isUlid($identifier)) {
|
||||
try {
|
||||
if (isset($user->username)) {
|
||||
$identifier = $user->username;
|
||||
} elseif (isset($user->email)) {
|
||||
$identifier = $user->email;
|
||||
} elseif (isset($user->name)) {
|
||||
$identifier = Str::limit($user->name, 24);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => $identifier,
|
||||
'user' => $user instanceof Arrayable ? $user->toArray() : $user,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'auth';
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
$widgets = [];
|
||||
|
||||
if ($this->showGuardsData) {
|
||||
$widgets["auth"] = [
|
||||
"icon" => "lock",
|
||||
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
|
||||
"map" => "auth.guards",
|
||||
"default" => "{}",
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->showName) {
|
||||
$widgets['auth.name'] = [
|
||||
'icon' => 'user',
|
||||
'tooltip' => 'Auth status',
|
||||
'map' => 'auth.names',
|
||||
'default' => '',
|
||||
];
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
}
|
685
vendor/barryvdh/laravel-debugbar/src/DataCollector/QueryCollector.php
vendored
Normal file
685
vendor/barryvdh/laravel-debugbar/src/DataCollector/QueryCollector.php
vendored
Normal file
@ -0,0 +1,685 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\PDO\PDOCollector;
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Collects data about SQL statements executed with PDO
|
||||
*/
|
||||
class QueryCollector extends PDOCollector
|
||||
{
|
||||
protected $timeCollector;
|
||||
protected $queries = [];
|
||||
protected $queryCount = 0;
|
||||
protected $softLimit = null;
|
||||
protected $hardLimit = null;
|
||||
protected $lastMemoryUsage;
|
||||
protected $renderSqlWithParams = false;
|
||||
protected $findSource = false;
|
||||
protected $middleware = [];
|
||||
protected $durationBackground = true;
|
||||
protected $explainQuery = false;
|
||||
protected $explainTypes = ['SELECT']; // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+
|
||||
protected $showHints = false;
|
||||
protected $showCopyButton = false;
|
||||
protected $reflection = [];
|
||||
protected $backtraceExcludePaths = [
|
||||
'/vendor/laravel/framework/src/Illuminate/Support',
|
||||
'/vendor/laravel/framework/src/Illuminate/Database',
|
||||
'/vendor/laravel/framework/src/Illuminate/Events',
|
||||
'/vendor/laravel/framework/src/Illuminate/Collections',
|
||||
'/vendor/october/rain',
|
||||
'/vendor/barryvdh/laravel-debugbar',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param TimeDataCollector $timeCollector
|
||||
*/
|
||||
public function __construct(TimeDataCollector $timeCollector = null)
|
||||
{
|
||||
$this->timeCollector = $timeCollector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $softLimit After the soft limit, no parameters/backtrace are captured
|
||||
* @param int|null $hardLimit After the hard limit, queries are ignored
|
||||
* @return void
|
||||
*/
|
||||
public function setLimits(?int $softLimit, ?int $hardLimit): void
|
||||
{
|
||||
$this->softLimit = $softLimit;
|
||||
$this->hardLimit = $hardLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the SQL of traced statements with params embedded
|
||||
*
|
||||
* @param boolean $enabled
|
||||
* @param string $quotationChar NOT USED
|
||||
*/
|
||||
public function setRenderSqlWithParams($enabled = true, $quotationChar = "'")
|
||||
{
|
||||
$this->renderSqlWithParams = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide the hints in the parameters
|
||||
*
|
||||
* @param boolean $enabled
|
||||
*/
|
||||
public function setShowHints($enabled = true)
|
||||
{
|
||||
$this->showHints = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide copy button next to the queries
|
||||
*
|
||||
* @param boolean $enabled
|
||||
*/
|
||||
public function setShowCopyButton($enabled = true)
|
||||
{
|
||||
$this->showCopyButton = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable finding the source
|
||||
*
|
||||
* @param bool|int $value
|
||||
* @param array $middleware
|
||||
*/
|
||||
public function setFindSource($value, array $middleware)
|
||||
{
|
||||
$this->findSource = $value;
|
||||
$this->middleware = $middleware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional paths to exclude from the backtrace
|
||||
*
|
||||
* @param array $excludePaths Array of file paths to exclude from backtrace
|
||||
*/
|
||||
public function mergeBacktraceExcludePaths(array $excludePaths)
|
||||
{
|
||||
$this->backtraceExcludePaths = array_merge($this->backtraceExcludePaths, $excludePaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable the shaded duration background on queries
|
||||
*
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setDurationBackground($enabled = true)
|
||||
{
|
||||
$this->durationBackground = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable the EXPLAIN queries
|
||||
*
|
||||
* @param bool $enabled
|
||||
* @param array|null $types Array of types to explain queries (select/insert/update/delete)
|
||||
*/
|
||||
public function setExplainSource($enabled, $types)
|
||||
{
|
||||
$this->explainQuery = $enabled;
|
||||
// workaround ['SELECT'] only. https://github.com/barryvdh/laravel-debugbar/issues/888
|
||||
// if($types){
|
||||
// $this->explainTypes = $types;
|
||||
// }
|
||||
}
|
||||
|
||||
public function startMemoryUsage()
|
||||
{
|
||||
$this->lastMemoryUsage = memory_get_usage(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Illuminate\Database\Events\QueryExecuted $query
|
||||
*/
|
||||
public function addQuery($query)
|
||||
{
|
||||
$this->queryCount++;
|
||||
|
||||
if ($this->hardLimit && $this->queryCount > $this->hardLimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limited = $this->softLimit && $this->queryCount > $this->softLimit;
|
||||
|
||||
$sql = (string) $query->sql;
|
||||
$explainResults = [];
|
||||
$time = $query->time / 1000;
|
||||
$endTime = microtime(true);
|
||||
$startTime = $endTime - $time;
|
||||
$hints = $this->performQueryAnalysis($sql);
|
||||
|
||||
$pdo = null;
|
||||
try {
|
||||
$pdo = $query->connection->getPdo();
|
||||
} catch (\Throwable $e) {
|
||||
// ignore error for non-pdo laravel drivers
|
||||
}
|
||||
$bindings = $query->connection->prepareBindings($query->bindings);
|
||||
|
||||
// Run EXPLAIN on this query (if needed)
|
||||
if (!$limited && $this->explainQuery && $pdo && preg_match('/^\s*(' . implode('|', $this->explainTypes) . ') /i', $sql)) {
|
||||
$statement = $pdo->prepare('EXPLAIN ' . $sql);
|
||||
$statement->execute($bindings);
|
||||
$explainResults = $statement->fetchAll(\PDO::FETCH_CLASS);
|
||||
}
|
||||
|
||||
$bindings = $this->getDataFormatter()->checkBindings($bindings);
|
||||
if (!empty($bindings) && $this->renderSqlWithParams) {
|
||||
foreach ($bindings as $key => $binding) {
|
||||
// This regex matches placeholders only, not the question marks,
|
||||
// nested in quotes, while we iterate through the bindings
|
||||
// and substitute placeholders by suitable values.
|
||||
$regex = is_numeric($key)
|
||||
? "/(?<!\?)\?(?=(?:[^'\\\']*'[^'\\']*')*[^'\\\']*$)(?!\?)/"
|
||||
: "/:{$key}(?=(?:[^'\\\']*'[^'\\\']*')*[^'\\\']*$)/";
|
||||
|
||||
// Mimic bindValue and only quote non-integer and non-float data types
|
||||
if (!is_int($binding) && !is_float($binding)) {
|
||||
if ($pdo) {
|
||||
try {
|
||||
$binding = $pdo->quote((string) $binding);
|
||||
} catch (\Exception $e) {
|
||||
$binding = $this->emulateQuote($binding);
|
||||
}
|
||||
} else {
|
||||
$binding = $this->emulateQuote($binding);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = preg_replace($regex, addcslashes($binding, '$'), $sql, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$source = [];
|
||||
|
||||
if (!$limited && $this->findSource) {
|
||||
try {
|
||||
$source = $this->findSource();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
$this->queries[] = [
|
||||
'query' => $sql,
|
||||
'type' => 'query',
|
||||
'bindings' => !$limited ? $this->getDataFormatter()->escapeBindings($bindings) : null,
|
||||
'start' => $startTime,
|
||||
'time' => $time,
|
||||
'memory' => $this->lastMemoryUsage ? memory_get_usage(false) - $this->lastMemoryUsage : 0,
|
||||
'source' => $source,
|
||||
'explain' => $explainResults,
|
||||
'connection' => $query->connection->getDatabaseName(),
|
||||
'driver' => $query->connection->getConfig('driver'),
|
||||
'hints' => ($this->showHints && !$limited) ? $hints : null,
|
||||
'show_copy' => $this->showCopyButton,
|
||||
];
|
||||
|
||||
if ($this->timeCollector !== null) {
|
||||
$this->timeCollector->addMeasure(Str::limit($sql, 100), $startTime, $endTime, [], 'db');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mimic mysql_real_escape_string
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function emulateQuote($value)
|
||||
{
|
||||
$search = ["\\", "\x00", "\n", "\r", "'", '"', "\x1a"];
|
||||
$replace = ["\\\\","\\0","\\n", "\\r", "\'", '\"', "\\Z"];
|
||||
|
||||
return "'" . str_replace($search, $replace, (string) $value) . "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Explainer::performQueryAnalysis()
|
||||
*
|
||||
* Perform simple regex analysis on the code
|
||||
*
|
||||
* @package xplain (https://github.com/rap2hpoutre/mysql-xplain-xplain)
|
||||
* @author e-doceo
|
||||
* @copyright 2014
|
||||
* @version $Id$
|
||||
* @access public
|
||||
* @param string $query
|
||||
* @return string[]
|
||||
*/
|
||||
protected function performQueryAnalysis($query)
|
||||
{
|
||||
// @codingStandardsIgnoreStart
|
||||
$hints = [];
|
||||
if (preg_match('/^\\s*SELECT\\s*`?[a-zA-Z0-9]*`?\\.?\\*/i', $query)) {
|
||||
$hints[] = 'Use <code>SELECT *</code> only if you need all columns from table';
|
||||
}
|
||||
if (preg_match('/ORDER BY RAND()/i', $query)) {
|
||||
$hints[] = '<code>ORDER BY RAND()</code> is slow, try to avoid if you can.
|
||||
You can <a href="https://stackoverflow.com/questions/2663710/how-does-mysqls-order-by-rand-work" target="_blank">read this</a>
|
||||
or <a href="https://stackoverflow.com/questions/1244555/how-can-i-optimize-mysqls-order-by-rand-function" target="_blank">this</a>';
|
||||
}
|
||||
if (strpos($query, '!=') !== false) {
|
||||
$hints[] = 'The <code>!=</code> operator is not standard. Use the <code><></code> operator to test for inequality instead.';
|
||||
}
|
||||
if (stripos($query, 'WHERE') === false && preg_match('/^(SELECT) /i', $query)) {
|
||||
$hints[] = 'The <code>SELECT</code> statement has no <code>WHERE</code> clause and could examine many more rows than intended';
|
||||
}
|
||||
if (preg_match('/LIMIT\\s/i', $query) && stripos($query, 'ORDER BY') === false) {
|
||||
$hints[] = '<code>LIMIT</code> without <code>ORDER BY</code> causes non-deterministic results, depending on the query execution plan';
|
||||
}
|
||||
if (preg_match('/LIKE\\s[\'"](%.*?)[\'"]/i', $query, $matches)) {
|
||||
$hints[] = 'An argument has a leading wildcard character: <code>' . $matches[1] . '</code>.
|
||||
The predicate with this argument is not sargable and cannot use an index if one exists.';
|
||||
}
|
||||
return $hints;
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a backtrace to search for the origins of the query.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function findSource()
|
||||
{
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT, app('config')->get('debugbar.debug_backtrace_limit', 50));
|
||||
|
||||
$sources = [];
|
||||
|
||||
foreach ($stack as $index => $trace) {
|
||||
$sources[] = $this->parseTrace($index, $trace);
|
||||
}
|
||||
|
||||
return array_slice(array_filter($sources), 0, is_int($this->findSource) ? $this->findSource : 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a trace element from the backtrace stack.
|
||||
*
|
||||
* @param int $index
|
||||
* @param array $trace
|
||||
* @return object|bool
|
||||
*/
|
||||
protected function parseTrace($index, array $trace)
|
||||
{
|
||||
$frame = (object) [
|
||||
'index' => $index,
|
||||
'namespace' => null,
|
||||
'name' => null,
|
||||
'file' => null,
|
||||
'line' => $trace['line'] ?? '1',
|
||||
];
|
||||
|
||||
if (isset($trace['function']) && $trace['function'] == 'substituteBindings') {
|
||||
$frame->name = 'Route binding';
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($trace['class']) &&
|
||||
isset($trace['file']) &&
|
||||
!$this->fileIsInExcludedPath($trace['file'])
|
||||
) {
|
||||
$frame->file = $trace['file'];
|
||||
|
||||
if (isset($trace['object']) && is_a($trace['object'], '\Twig\Template')) {
|
||||
list($frame->file, $frame->line) = $this->getTwigInfo($trace);
|
||||
} elseif (strpos($frame->file, storage_path()) !== false) {
|
||||
$hash = pathinfo($frame->file, PATHINFO_FILENAME);
|
||||
|
||||
if ($frame->name = $this->findViewFromHash($hash)) {
|
||||
$frame->file = $frame->name[1];
|
||||
$frame->name = $frame->name[0];
|
||||
} else {
|
||||
$frame->name = $hash;
|
||||
}
|
||||
|
||||
$frame->namespace = 'view';
|
||||
|
||||
return $frame;
|
||||
} elseif (strpos($frame->file, 'Middleware') !== false) {
|
||||
$frame->name = $this->findMiddlewareFromFile($frame->file);
|
||||
|
||||
if ($frame->name) {
|
||||
$frame->namespace = 'middleware';
|
||||
} else {
|
||||
$frame->name = $this->normalizeFilePath($frame->file);
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
$frame->name = $this->normalizeFilePath($frame->file);
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given file is to be excluded from analysis
|
||||
*
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
protected function fileIsInExcludedPath($file)
|
||||
{
|
||||
$normalizedPath = str_replace('\\', '/', $file);
|
||||
|
||||
foreach ($this->backtraceExcludePaths as $excludedPath) {
|
||||
if (strpos($normalizedPath, $excludedPath) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the middleware alias from the file.
|
||||
*
|
||||
* @param string $file
|
||||
* @return string|null
|
||||
*/
|
||||
protected function findMiddlewareFromFile($file)
|
||||
{
|
||||
$filename = pathinfo($file, PATHINFO_FILENAME);
|
||||
|
||||
foreach ($this->middleware as $alias => $class) {
|
||||
if (strpos($class, $filename) !== false) {
|
||||
return $alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the template name from the hash.
|
||||
*
|
||||
* @param string $hash
|
||||
* @return null|array
|
||||
*/
|
||||
protected function findViewFromHash($hash)
|
||||
{
|
||||
$finder = app('view')->getFinder();
|
||||
|
||||
if (isset($this->reflection['viewfinderViews'])) {
|
||||
$property = $this->reflection['viewfinderViews'];
|
||||
} else {
|
||||
$reflection = new \ReflectionClass($finder);
|
||||
$property = $reflection->getProperty('views');
|
||||
$property->setAccessible(true);
|
||||
$this->reflection['viewfinderViews'] = $property;
|
||||
}
|
||||
|
||||
$xxh128Exists = in_array('xxh128', hash_algos());
|
||||
|
||||
foreach ($property->getValue($finder) as $name => $path) {
|
||||
if (($xxh128Exists && hash('xxh128', 'v2' . $path) == $hash) || sha1('v2' . $path) == $hash) {
|
||||
return [$name, $path];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename/line from a Twig template trace
|
||||
*
|
||||
* @param array $trace
|
||||
* @return array The file and line
|
||||
*/
|
||||
protected function getTwigInfo($trace)
|
||||
{
|
||||
$file = $trace['object']->getTemplateName();
|
||||
|
||||
if (isset($trace['line'])) {
|
||||
foreach ($trace['object']->getDebugInfo() as $codeLine => $templateLine) {
|
||||
if ($codeLine <= $trace['line']) {
|
||||
return [$file, $templateLine];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$file, -1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect a database transaction event.
|
||||
* @param string $event
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function collectTransactionEvent($event, $connection)
|
||||
{
|
||||
$source = [];
|
||||
|
||||
if ($this->findSource) {
|
||||
try {
|
||||
$source = $this->findSource();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
$this->queries[] = [
|
||||
'query' => $event,
|
||||
'type' => 'transaction',
|
||||
'bindings' => [],
|
||||
'start' => microtime(true),
|
||||
'time' => 0,
|
||||
'memory' => 0,
|
||||
'source' => $source,
|
||||
'explain' => [],
|
||||
'connection' => $connection->getDatabaseName(),
|
||||
'driver' => $connection->getConfig('driver'),
|
||||
'hints' => null,
|
||||
'show_copy' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the queries.
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->queries = [];
|
||||
$this->queryCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$totalTime = 0;
|
||||
$totalMemory = 0;
|
||||
$queries = $this->queries;
|
||||
|
||||
$statements = [];
|
||||
foreach ($queries as $query) {
|
||||
$source = reset($query['source']);
|
||||
$totalTime += $query['time'];
|
||||
$totalMemory += $query['memory'];
|
||||
|
||||
if (str_ends_with($query['connection'], '.sqlite')) {
|
||||
$query['connection'] = $this->normalizeFilePath($query['connection']);
|
||||
}
|
||||
|
||||
$statements[] = [
|
||||
'sql' => $this->getDataFormatter()->formatSql($query['query']),
|
||||
'type' => $query['type'],
|
||||
'params' => [],
|
||||
'bindings' => $query['bindings'],
|
||||
'hints' => $query['hints'],
|
||||
'show_copy' => $query['show_copy'],
|
||||
'backtrace' => array_values($query['source']),
|
||||
'start' => $query['start'] ?? null,
|
||||
'duration' => $query['time'],
|
||||
'duration_str' => ($query['type'] == 'transaction') ? '' : $this->formatDuration($query['time']),
|
||||
'memory' => $query['memory'],
|
||||
'memory_str' => $query['memory'] ? $this->getDataFormatter()->formatBytes($query['memory']) : null,
|
||||
'filename' => $this->getDataFormatter()->formatSource($source, true),
|
||||
'source' => $this->getDataFormatter()->formatSource($source),
|
||||
'xdebug_link' => is_object($source) ? $this->getXdebugLink($source->file ?: '', $source->line) : null,
|
||||
'connection' => $query['connection'],
|
||||
];
|
||||
|
||||
if ($query['explain']) {
|
||||
// Add the results from the EXPLAIN as new rows
|
||||
if ($query['driver'] === 'pgsql') {
|
||||
$explainer = trim(implode("\n", array_map(function ($explain) {
|
||||
return $explain->{'QUERY PLAN'};
|
||||
}, $query['explain'])));
|
||||
|
||||
if ($explainer) {
|
||||
$statements[] = [
|
||||
'sql' => " - EXPLAIN: {$explainer}",
|
||||
'type' => 'explain',
|
||||
];
|
||||
}
|
||||
} elseif ($query['driver'] === 'sqlite') {
|
||||
$vmi = '<table style="margin:-5px -11px !important;width: 100% !important">';
|
||||
$vmi .= "<thead><tr>
|
||||
<td>Address</td>
|
||||
<td>Opcode</td>
|
||||
<td>P1</td>
|
||||
<td>P2</td>
|
||||
<td>P3</td>
|
||||
<td>P4</td>
|
||||
<td>P5</td>
|
||||
<td>Comment</td>
|
||||
</tr></thead>";
|
||||
|
||||
foreach ($query['explain'] as $explain) {
|
||||
$vmi .= "<tr>
|
||||
<td>{$explain->addr}</td>
|
||||
<td>{$explain->opcode}</td>
|
||||
<td>{$explain->p1}</td>
|
||||
<td>{$explain->p2}</td>
|
||||
<td>{$explain->p3}</td>
|
||||
<td>{$explain->p4}</td>
|
||||
<td>{$explain->p5}</td>
|
||||
<td>{$explain->comment}</td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
$vmi .= '</table>';
|
||||
|
||||
$statements[] = [
|
||||
'sql' => " - EXPLAIN:",
|
||||
'type' => 'explain',
|
||||
'params' => [
|
||||
'Virtual Machine Instructions' => $vmi,
|
||||
]
|
||||
];
|
||||
} else {
|
||||
foreach ($query['explain'] as $explain) {
|
||||
$statements[] = [
|
||||
'sql' => " - EXPLAIN # {$explain->id}: `{$explain->table}` ({$explain->select_type})",
|
||||
'type' => 'explain',
|
||||
'params' => $explain,
|
||||
'row_count' => $explain->rows,
|
||||
'stmt_id' => $explain->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->durationBackground) {
|
||||
if ($totalTime > 0) {
|
||||
// For showing background measure on Queries tab
|
||||
$start_percent = 0;
|
||||
|
||||
foreach ($statements as $i => $statement) {
|
||||
if (!isset($statement['duration'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$width_percent = $statement['duration'] / $totalTime * 100;
|
||||
|
||||
$statements[$i] = array_merge($statement, [
|
||||
'start_percent' => round($start_percent, 3),
|
||||
'width_percent' => round($width_percent, 3),
|
||||
]);
|
||||
|
||||
$start_percent += $width_percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->softLimit && $this->hardLimit && ($this->queryCount > $this->softLimit && $this->queryCount > $this->hardLimit)) {
|
||||
array_unshift($statements, [
|
||||
'sql' => '# Query soft and hard limit for Debugbar are reached. Only the first ' . $this->softLimit . ' queries show details. Queries after the first ' . $this->hardLimit . ' are ignored. Limits can be raised in the config (debugbar.options.db.soft/hard_limit).',
|
||||
'type' => 'info',
|
||||
]);
|
||||
$statements[] = [
|
||||
'sql' => '... ' . ($this->queryCount - $this->hardLimit) . ' additional queries are executed but now shown because of Debugbar query limits. Limits can be raised in the config (debugbar.options.db.soft/hard_limit)',
|
||||
'type' => 'info',
|
||||
];
|
||||
} elseif ($this->hardLimit && $this->queryCount > $this->hardLimit) {
|
||||
array_unshift($statements, [
|
||||
'sql' => '# Query hard limit for Debugbar is reached after ' . $this->hardLimit . ' queries, additional ' . ($this->queryCount - $this->hardLimit) . ' queries are not shown.. Limits can be raised in the config (debugbar.options.db.hard_limit)',
|
||||
'type' => 'info',
|
||||
]);
|
||||
$statements[] = [
|
||||
'sql' => '... ' . ($this->queryCount - $this->hardLimit) . ' additional queries are executed but now shown because of Debugbar query limits. Limits can be raised in the config (debugbar.options.db.hard_limit)',
|
||||
'type' => 'info',
|
||||
];
|
||||
} elseif ($this->softLimit && $this->queryCount > $this->softLimit) {
|
||||
array_unshift($statements, [
|
||||
'sql' => '# Query soft limit for Debugbar is reached after ' . $this->softLimit . ' queries, additional ' . ($this->queryCount - $this->softLimit) . ' queries only show the query. Limit can be raised in the config. Limits can be raised in the config (debugbar.options.db.soft_limit)',
|
||||
'type' => 'info',
|
||||
]);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'nb_statements' => $this->queryCount,
|
||||
'nb_failed_statements' => 0,
|
||||
'accumulated_duration' => $totalTime,
|
||||
'accumulated_duration_str' => $this->formatDuration($totalTime),
|
||||
'memory_usage' => $totalMemory,
|
||||
'memory_usage_str' => $totalMemory ? $this->getDataFormatter()->formatBytes($totalMemory) : null,
|
||||
'statements' => $statements
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'queries';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"queries" => [
|
||||
"icon" => "database",
|
||||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
|
||||
"map" => "queries",
|
||||
"default" => "[]"
|
||||
],
|
||||
"queries:badge" => [
|
||||
"map" => "queries.nb_statements",
|
||||
"default" => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
194
vendor/barryvdh/laravel-debugbar/src/DataCollector/RequestCollector.php
vendored
Normal file
194
vendor/barryvdh/laravel-debugbar/src/DataCollector/RequestCollector.php
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Telescope\IncomingEntry;
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
*
|
||||
* Based on \Symfony\Component\HttpKernel\DataCollector\RequestDataCollector by Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
*/
|
||||
class RequestCollector extends DataCollector implements DataCollectorInterface, Renderable
|
||||
{
|
||||
/** @var \Symfony\Component\HttpFoundation\Request $request */
|
||||
protected $request;
|
||||
/** @var \Symfony\Component\HttpFoundation\Request $response */
|
||||
protected $response;
|
||||
/** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
|
||||
protected $session;
|
||||
/** @var string|null */
|
||||
protected $currentRequestId;
|
||||
/** @var array */
|
||||
protected $hiddens;
|
||||
|
||||
/**
|
||||
* Create a new SymfonyRequestCollector
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Symfony\Component\HttpFoundation\Response $response
|
||||
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
|
||||
* @param string|null $currentRequestId
|
||||
* @param array $hiddens
|
||||
*/
|
||||
public function __construct($request, $response, $session = null, $currentRequestId = null, $hiddens = [])
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
$this->session = $session;
|
||||
$this->currentRequestId = $currentRequestId;
|
||||
$this->hiddens = array_merge($hiddens, [
|
||||
'request_request.password',
|
||||
'request_headers.php-auth-pw.0',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'request';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"request" => [
|
||||
"icon" => "tags",
|
||||
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
|
||||
"map" => "request",
|
||||
"default" => "{}"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$request = $this->request;
|
||||
$response = $this->response;
|
||||
|
||||
$responseHeaders = $response->headers->all();
|
||||
$cookies = [];
|
||||
foreach ($response->headers->getCookies() as $cookie) {
|
||||
$cookies[] = $this->getCookieHeader(
|
||||
$cookie->getName(),
|
||||
$cookie->getValue(),
|
||||
$cookie->getExpiresTime(),
|
||||
$cookie->getPath(),
|
||||
$cookie->getDomain(),
|
||||
$cookie->isSecure(),
|
||||
$cookie->isHttpOnly()
|
||||
);
|
||||
}
|
||||
if (count($cookies) > 0) {
|
||||
$responseHeaders['Set-Cookie'] = $cookies;
|
||||
}
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
|
||||
$data = [
|
||||
'path_info' => $request->getPathInfo(),
|
||||
'status_code' => $statusCode,
|
||||
'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '',
|
||||
'format' => $request->getRequestFormat(),
|
||||
'content_type' => $response->headers->get('Content-Type') ? $response->headers->get(
|
||||
'Content-Type'
|
||||
) : 'text/html',
|
||||
'request_query' => $request->query->all(),
|
||||
'request_request' => $request->request->all(),
|
||||
'request_headers' => $request->headers->all(),
|
||||
'request_cookies' => $request->cookies->all(),
|
||||
'response_headers' => $responseHeaders,
|
||||
];
|
||||
|
||||
if ($this->session) {
|
||||
$data['session_attributes'] = $this->session->all();
|
||||
}
|
||||
|
||||
if (isset($data['request_headers']['authorization'][0])) {
|
||||
$data['request_headers']['authorization'][0] = substr($data['request_headers']['authorization'][0], 0, 12) . '******';
|
||||
}
|
||||
|
||||
foreach ($this->hiddens as $key) {
|
||||
if (Arr::has($data, $key)) {
|
||||
Arr::set($data, $key, '******');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $key => $var) {
|
||||
if (!is_string($data[$key])) {
|
||||
$data[$key] = DataCollector::getDefaultVarDumper()->renderVar($var);
|
||||
} else {
|
||||
$data[$key] = e($data[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$htmlData = [];
|
||||
if (class_exists(Telescope::class)) {
|
||||
$entry = IncomingEntry::make([
|
||||
'requestId' => $this->currentRequestId,
|
||||
])->type('debugbar');
|
||||
Telescope::$entriesQueue[] = $entry;
|
||||
$url = route('debugbar.telescope', [$entry->uuid]);
|
||||
$htmlData['telescope'] = '<a href="' . $url . '" target="_blank">View in Telescope</a>';
|
||||
}
|
||||
|
||||
return $htmlData + $data;
|
||||
}
|
||||
|
||||
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)
|
||||
{
|
||||
$cookie = sprintf('%s=%s', $name, urlencode($value));
|
||||
|
||||
if (0 !== $expires) {
|
||||
if (is_numeric($expires)) {
|
||||
$expires = (int) $expires;
|
||||
} elseif ($expires instanceof \DateTime) {
|
||||
$expires = $expires->getTimestamp();
|
||||
} else {
|
||||
$expires = strtotime($expires);
|
||||
if (false === $expires || -1 == $expires) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('The "expires" cookie parameter is not valid.', $expires)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$cookie .= '; expires=' . substr(
|
||||
\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'),
|
||||
0,
|
||||
-5
|
||||
);
|
||||
}
|
||||
|
||||
if ($domain) {
|
||||
$cookie .= '; domain=' . $domain;
|
||||
}
|
||||
|
||||
$cookie .= '; path=' . $path;
|
||||
|
||||
if ($secure) {
|
||||
$cookie .= '; secure';
|
||||
}
|
||||
|
||||
if ($httponly) {
|
||||
$cookie .= '; httponly';
|
||||
}
|
||||
|
||||
return $cookie;
|
||||
}
|
||||
}
|
177
vendor/barryvdh/laravel-debugbar/src/DataCollector/RouteCollector.php
vendored
Normal file
177
vendor/barryvdh/laravel-debugbar/src/DataCollector/RouteCollector.php
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use Closure;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Based on Illuminate\Foundation\Console\RoutesCommand for Taylor Otwell
|
||||
* https://github.com/laravel/framework/blob/master/src/Illuminate/Foundation/Console/RoutesCommand.php
|
||||
*
|
||||
*/
|
||||
class RouteCollector extends DataCollector implements Renderable
|
||||
{
|
||||
/**
|
||||
* The router instance.
|
||||
*
|
||||
* @var \Illuminate\Routing\Router
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
public function __construct(Router $router)
|
||||
{
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$route = $this->router->current();
|
||||
return $this->getRouteInformation($route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route information for a given route.
|
||||
*
|
||||
* @param \Illuminate\Routing\Route $route
|
||||
* @return array
|
||||
*/
|
||||
protected function getRouteInformation($route)
|
||||
{
|
||||
if (!is_a($route, 'Illuminate\Routing\Route')) {
|
||||
return [];
|
||||
}
|
||||
$uri = head($route->methods()) . ' ' . $route->uri();
|
||||
$action = $route->getAction();
|
||||
|
||||
$result = [
|
||||
'uri' => $uri ?: '-',
|
||||
];
|
||||
|
||||
$result = array_merge($result, $action);
|
||||
$uses = $action['uses'] ?? null;
|
||||
$controller = is_string($action['controller'] ?? null) ? $action['controller'] : '';
|
||||
|
||||
if (request()->hasHeader('X-Livewire')) {
|
||||
try {
|
||||
$component = request('components')[0];
|
||||
$name = json_decode($component['snapshot'], true)['memo']['name'];
|
||||
$method = $component['calls'][0]['method'];
|
||||
$class = app(\Livewire\Mechanisms\ComponentRegistry::class)->getClass($name);
|
||||
if (class_exists($class) && method_exists($class, $method)) {
|
||||
$controller = $class . '@' . $method;
|
||||
$result['controller'] = ltrim($controller, '\\');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
if (str_contains($controller, '@')) {
|
||||
list($controller, $method) = explode('@', $controller);
|
||||
if (class_exists($controller) && method_exists($controller, $method)) {
|
||||
$reflector = new \ReflectionMethod($controller, $method);
|
||||
}
|
||||
unset($result['uses']);
|
||||
} elseif ($uses instanceof \Closure) {
|
||||
$reflector = new \ReflectionFunction($uses);
|
||||
$result['uses'] = $this->formatVar($uses);
|
||||
} elseif (is_string($uses) && str_contains($uses, '@__invoke')) {
|
||||
if (class_exists($controller) && method_exists($controller, 'render')) {
|
||||
$reflector = new \ReflectionMethod($controller, 'render');
|
||||
$result['controller'] = $controller . '@render';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($reflector)) {
|
||||
$filename = $this->normalizeFilePath($reflector->getFileName());
|
||||
|
||||
if ($link = $this->getXdebugLink($reflector->getFileName(), $reflector->getStartLine())) {
|
||||
$result['file'] = sprintf(
|
||||
'<a href="%s" onclick="%s">%s:%s-%s</a>',
|
||||
$link['url'],
|
||||
$link['ajax'] ? 'event.preventDefault();$.ajax(this.href);' : '',
|
||||
$filename,
|
||||
$reflector->getStartLine(),
|
||||
$reflector->getEndLine()
|
||||
);
|
||||
} else {
|
||||
$result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine());
|
||||
}
|
||||
}
|
||||
|
||||
if ($middleware = $this->getMiddleware($route)) {
|
||||
$result['middleware'] = $middleware;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get middleware
|
||||
*
|
||||
* @param \Illuminate\Routing\Route $route
|
||||
* @return string
|
||||
*/
|
||||
protected function getMiddleware($route)
|
||||
{
|
||||
return implode(', ', array_map(function ($middleware) {
|
||||
return $middleware instanceof Closure ? 'Closure' : $middleware;
|
||||
}, $route->gatherMiddleware()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'route';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
$widgets = [
|
||||
"route" => [
|
||||
"icon" => "share",
|
||||
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
|
||||
"map" => "route",
|
||||
"default" => "{}"
|
||||
]
|
||||
];
|
||||
if (Config::get('debugbar.options.route.label', true)) {
|
||||
$widgets['currentroute'] = [
|
||||
"icon" => "share",
|
||||
"tooltip" => "Route",
|
||||
"map" => "route.uri",
|
||||
"default" => ""
|
||||
];
|
||||
}
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the route information on the console.
|
||||
*
|
||||
* @param array $routes
|
||||
* @return void
|
||||
*/
|
||||
protected function displayRoutes(array $routes)
|
||||
{
|
||||
$this->table->setHeaders($this->headers)->setRows($routes);
|
||||
|
||||
$this->table->render($this->getOutput());
|
||||
}
|
||||
}
|
71
vendor/barryvdh/laravel-debugbar/src/DataCollector/SessionCollector.php
vendored
Normal file
71
vendor/barryvdh/laravel-debugbar/src/DataCollector/SessionCollector.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SessionCollector extends DataCollector implements DataCollectorInterface, Renderable
|
||||
{
|
||||
/** @var \Symfony\Component\HttpFoundation\Session\SessionInterface|\Illuminate\Contracts\Session\Session $session */
|
||||
protected $session;
|
||||
/** @var array */
|
||||
protected $hiddens;
|
||||
|
||||
/**
|
||||
* Create a new SessionCollector
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface|\Illuminate\Contracts\Session\Session $session
|
||||
* @param array $hiddens
|
||||
*/
|
||||
public function __construct($session, $hiddens = [])
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->hiddens = $hiddens;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
$data = $this->session->all();
|
||||
|
||||
foreach ($this->hiddens as $key) {
|
||||
if (Arr::has($data, $key)) {
|
||||
Arr::set($data, $key, '******');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = is_string($value) ? $value : $this->formatVar($value);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'session';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
"session" => [
|
||||
"icon" => "archive",
|
||||
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
|
||||
"map" => "session",
|
||||
"default" => "{}"
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
199
vendor/barryvdh/laravel-debugbar/src/DataCollector/ViewCollector.php
vendored
Normal file
199
vendor/barryvdh/laravel-debugbar/src/DataCollector/ViewCollector.php
vendored
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace Barryvdh\Debugbar\DataCollector;
|
||||
|
||||
use Barryvdh\Debugbar\DataFormatter\SimpleFormatter;
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ViewCollector extends DataCollector implements Renderable, AssetProvider
|
||||
{
|
||||
protected $name;
|
||||
protected $templates = [];
|
||||
protected $collect_data;
|
||||
protected $exclude_paths;
|
||||
protected $group;
|
||||
|
||||
/**
|
||||
* Create a ViewCollector
|
||||
*
|
||||
* @param bool|string $collectData Collects view data when true
|
||||
* @param string[] $excludePaths Paths to exclude from collection
|
||||
* @param int|bool $group Group the same templates together
|
||||
* */
|
||||
public function __construct($collectData = true, $excludePaths = [], $group = true)
|
||||
{
|
||||
$this->setDataFormatter(new SimpleFormatter());
|
||||
$this->collect_data = $collectData;
|
||||
$this->templates = [];
|
||||
$this->exclude_paths = $excludePaths;
|
||||
$this->group = $group;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'views';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
'views' => [
|
||||
'icon' => 'leaf',
|
||||
'widget' => 'PhpDebugBar.Widgets.TemplatesWidget',
|
||||
'map' => 'views',
|
||||
'default' => '[]'
|
||||
],
|
||||
'views:badge' => [
|
||||
'map' => 'views.nb_templates',
|
||||
'default' => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAssets()
|
||||
{
|
||||
return [
|
||||
'css' => 'widgets/templates/widget.css',
|
||||
'js' => 'widgets/templates/widget.js',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a View instance to the Collector
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*/
|
||||
public function addView(View $view)
|
||||
{
|
||||
$name = $view->getName();
|
||||
$type = null;
|
||||
$data = $view->getData();
|
||||
$path = $view->getPath();
|
||||
|
||||
if (class_exists('\Inertia\Inertia')) {
|
||||
list($name, $type, $data, $path) = $this->getInertiaView($name, $data, $path);
|
||||
}
|
||||
|
||||
if (is_object($path)) {
|
||||
$type = get_class($view);
|
||||
$path = null;
|
||||
}
|
||||
|
||||
if ($path) {
|
||||
if (!$type) {
|
||||
if (substr($path, -10) == '.blade.php') {
|
||||
$type = 'blade';
|
||||
} else {
|
||||
$type = pathinfo($path, PATHINFO_EXTENSION);
|
||||
}
|
||||
}
|
||||
|
||||
$shortPath = $this->normalizeFilePath($path);
|
||||
foreach ($this->exclude_paths as $excludePath) {
|
||||
if (str_starts_with($shortPath, $excludePath)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->addTemplate($name, $data, $type, $path);
|
||||
}
|
||||
|
||||
private function getInertiaView(string $name, array $data, ?string $path)
|
||||
{
|
||||
if (isset($data['page']) && is_array($data['page'])) {
|
||||
$data = $data['page'];
|
||||
}
|
||||
|
||||
if (isset($data['props'], $data['component'])) {
|
||||
$name = $data['component'];
|
||||
$data = $data['props'];
|
||||
|
||||
if ($files = glob(resource_path('js/Pages/' . $name . '.*'))) {
|
||||
$path = $files[0];
|
||||
$type = pathinfo($path, PATHINFO_EXTENSION);
|
||||
|
||||
if (in_array($type, ['js', 'jsx'])) {
|
||||
$type = 'react';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$name, $type ?? '', $data, $path];
|
||||
}
|
||||
|
||||
public function addInertiaAjaxView(array $data)
|
||||
{
|
||||
list($name, $type, $data, $path) = $this->getInertiaView('', $data, '');
|
||||
|
||||
if (! $name) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addTemplate($name, $data, $type, $path);
|
||||
}
|
||||
|
||||
private function addTemplate(string $name, array $data, ?string $type, ?string $path)
|
||||
{
|
||||
// Prevent duplicates
|
||||
$hash = $type . $path . $name . ($this->collect_data ? implode(array_keys($data)) : '');
|
||||
|
||||
if ($this->collect_data === 'keys') {
|
||||
$params = array_keys($data);
|
||||
} elseif ($this->collect_data) {
|
||||
$params = array_map(
|
||||
fn ($value) => $this->getDataFormatter()->formatVar($value),
|
||||
$data
|
||||
);
|
||||
} else {
|
||||
$params = [];
|
||||
}
|
||||
|
||||
$template = [
|
||||
'name' => $name,
|
||||
'param_count' => $this->collect_data ? count($params) : null,
|
||||
'params' => $params,
|
||||
'start' => microtime(true),
|
||||
'type' => $type,
|
||||
'hash' => $hash,
|
||||
];
|
||||
|
||||
if ($path && $this->getXdebugLinkTemplate()) {
|
||||
$template['xdebug_link'] = $this->getXdebugLink($path);
|
||||
}
|
||||
|
||||
$this->templates[] = $template;
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
if ($this->group === true || count($this->templates) > $this->group) {
|
||||
$templates = [];
|
||||
foreach ($this->templates as $template) {
|
||||
$hash = $template['hash'];
|
||||
if (!isset($templates[$hash])) {
|
||||
$template['render_count'] = 0;
|
||||
$template['name_original'] = $template['name'];
|
||||
$templates[$hash] = $template;
|
||||
}
|
||||
|
||||
$templates[$hash]['render_count']++;
|
||||
$templates[$hash]['name'] = $templates[$hash]['render_count'] . 'x ' . $templates[$hash]['name_original'];
|
||||
}
|
||||
$templates = array_values($templates);
|
||||
} else {
|
||||
$templates = $this->templates;
|
||||
}
|
||||
|
||||
return [
|
||||
'nb_templates' => count($this->templates),
|
||||
'templates' => $templates,
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user