Skip to content

Commit

Permalink
refactor: change modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Dec 27, 2021
1 parent 415a39c commit 7fae5c6
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 75 deletions.
14 changes: 7 additions & 7 deletions src/BarManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ class BarManager
*
* @var array
*/
protected $panels = [];
private $panels = [];

/**
* $bar.
*
* @var Bar
*/
protected $bar;
private $bar;

/**
* $request.
*
* @var Request
*/
protected $request;
private $request;

/**
* @var Application
*/
protected $app;
private $app;

/**
* __construct.
Expand Down Expand Up @@ -99,7 +99,7 @@ public function loadPanels($panels = [])
* @param string $id
* @return IBarPanel
*/
public static function make($id)
private static function make($id)
{
$className = static::name($id);

Expand Down Expand Up @@ -139,7 +139,7 @@ public function get($id)
* @param string $id
* @return bool
*/
protected function isAjaxPanel($id)
private function isAjaxPanel($id)
{
return is_subclass_of(static::name($id), IAjaxPanel::class) === true;
}
Expand All @@ -150,7 +150,7 @@ protected function isAjaxPanel($id)
* @param string $id
* @return string
*/
protected static function name($id)
private static function name($id)
{
return '\\'.__NAMESPACE__.'\Panels\\'.Str::studly($id).'Panel';
}
Expand Down
51 changes: 16 additions & 35 deletions src/DebuggerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use ErrorException;
use Exception;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Support\Arr;
use Throwable;
use Tracy\Bar;
Expand All @@ -17,33 +16,30 @@ class DebuggerManager
/**
* @var array
*/
protected $config;
private $config;

/**
* $bar.
*
* @var Bar
*/
protected $bar;
private $bar;

/**
* @var BlueScreen
*/
protected $blueScreen;
private $blueScreen;

/**
* $session.
*
* @var Session
*/
protected $session;

private $session;
/**
* $urlGenerator.
*
* @var UrlGenerator
* @var null
*/
protected $urlGenerator;
private $url;

/**
* __construct.
Expand All @@ -52,13 +48,15 @@ class DebuggerManager
* @param Bar $bar
* @param BlueScreen $blueScreen
* @param Session|null $session
* @param null $url
*/
public function __construct($config = [], Bar $bar = null, BlueScreen $blueScreen = null, Session $session = null)
public function __construct($config = [], Bar $bar = null, BlueScreen $blueScreen = null, Session $session = null, $url = null)
{
$this->config = $config;
$this->bar = $bar ?: Debugger::getBar();
$this->blueScreen = $blueScreen ?: Debugger::getBlueScreen();
$this->session = $session ?: new Session;
$this->url = $url;
}

/**
Expand Down Expand Up @@ -128,19 +126,6 @@ public function accepts()
return Arr::get($this->config, 'accepts', []);
}

/**
* setUrlGenerator.
*
* @param UrlGenerator $urlGenerator
* @return $this
*/
public function setUrlGenerator(UrlGenerator $urlGenerator)
{
$this->urlGenerator = $urlGenerator;

return $this;
}

/**
* dispatchAssets.
*
Expand Down Expand Up @@ -235,7 +220,7 @@ public function exceptionHandler(Throwable $exception)
* @param bool $ajax
* @return string
*/
protected function renderLoader($content, $ajax = false)
private function renderLoader($content, $ajax = false)
{
if ($ajax === true || $this->session->isStarted() === false) {
return $content;
Expand All @@ -250,7 +235,7 @@ protected function renderLoader($content, $ajax = false)
* @param string $content
* @return string
*/
protected function renderBar($content)
private function renderBar($content)
{
return $this->render(
$content,
Expand All @@ -267,7 +252,7 @@ protected function renderBar($content)
* @param string[] $appendTags
* @return string
*/
protected function render($content, $method, $appendTags = ['body'])
private function render($content, $method, $appendTags = ['body'])
{
$appendHtml = $this->renderBuffer(function () use ($method) {
$requestUri = Arr::get($_SERVER, 'REQUEST_URI');
Expand Down Expand Up @@ -295,7 +280,7 @@ protected function render($content, $method, $appendTags = ['body'])
* @param callable $callback
* @return string
*/
protected function renderBuffer(callable $callback)
private function renderBuffer(callable $callback)
{
ob_start();
$callback();
Expand All @@ -309,14 +294,10 @@ protected function renderBuffer(callable $callback)
* @param string $content
* @return string
*/
protected function replacePath($content)
private function replacePath($content)
{
$path = is_null($this->urlGenerator) === false
? $this->urlGenerator->route(Arr::get($this->config, 'route.as').'bar')
: null;

return is_null($path) === false
? str_replace('?_tracy_bar', $path.'?_tracy_bar', $content)
return $this->url
? str_replace('?_tracy_bar', $this->url.'?_tracy_bar', $content)
: $content;
}
}
10 changes: 7 additions & 3 deletions src/LaravelTracyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ public function register()
});

$this->app->bind(DebuggerManager::class, function ($app) use ($config) {
return (new DebuggerManager(
DebuggerManager::init($config), $app[Bar::class], $app[BlueScreen::class], new Session
))->setUrlGenerator($app['url']);
return new DebuggerManager(
DebuggerManager::init($config),
$app[Bar::class],
$app[BlueScreen::class],
new Session,
$app['url']->route(Arr::get($config, 'route.as').'bar')
);
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/Middleware/RenderBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class RenderBar
/**
* @var DebuggerManager
*/
protected $debuggerManager;
private $debuggerManager;
/**
* @var Dispatcher
*/
protected $events;
private $events;

/**
* __construct.
Expand Down Expand Up @@ -56,7 +56,7 @@ public function handle($request, $next)
* @param Closure $next
* @return Response
*/
protected function keepFlashSession($request, $next)
private function keepFlashSession($request, $next)
{
$type = $request->get('_tracy_bar');
if ($request->hasSession() === true && in_array($type, ['js', 'css'], true) === false) {
Expand All @@ -73,15 +73,15 @@ protected function keepFlashSession($request, $next)
* @param Closure $next
* @return Response
*/
protected function render($request, $next)
private function render($request, $next)
{
$this->debuggerManager->dispatch();

$response = $next($request);

$ajax = $request->ajax();

if ($this->reject($response, $request, $ajax) === true) {
if ($this->reject($response, $ajax) === true) {
return $response;
}

Expand All @@ -90,7 +90,8 @@ protected function render($request, $next)

$response->setContent(
$this->debuggerManager->shutdownHandler(
$response->getContent(), $ajax
$response->getContent(),
$ajax
)
);

Expand All @@ -101,12 +102,11 @@ protected function render($request, $next)
* reject.
*
* @param Response $response
* @param Request $request
* @param bool $ajax
*
* @return bool
*/
protected function reject(Response $response, Request $request, $ajax)
private function reject(Response $response, $ajax)
{
if (
$response instanceof BinaryFileResponse ||
Expand Down
10 changes: 5 additions & 5 deletions src/Panels/AbstractPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ abstract class AbstractPanel implements IBarPanel, ILaravelPanel
/**
* @var mixed
*/
protected $attributes;
private $attributes;
/**
* @var string
*/
protected $viewPath;
private $viewPath;
/**
* @var Template
*/
Expand Down Expand Up @@ -105,7 +105,7 @@ protected function render($view)
*
* @return string
*/
protected function getViewPath()
private function getViewPath()
{
if (is_null($this->viewPath) === false) {
return $this->viewPath;
Expand Down Expand Up @@ -140,9 +140,9 @@ protected static function findSource()
}

if (isset($row['class']) === true && (
is_subclass_of($row['class'], IBarPanel::class) === true ||
is_subclass_of($row['class'], IBarPanel::class) === true ||
strpos(str_replace('/', '\\', $row['file']), 'Illuminate\\') !== false
)) {
)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Panels/AuthPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function getAttributes()
$attributes = [];
if (is_null($this->userResolver) === false) {
$attributes['rows'] = call_user_func($this->userResolver);
} else if ($this->hasLaravel() === true) {
} elseif ($this->hasLaravel() === true) {
$attributes = isset($this->laravel['sentinel']) === true ?
$this->fromSentinel() : $this->fromGuard();
}
Expand Down Expand Up @@ -90,7 +90,7 @@ protected function identifier($attributes = [])

if (empty($rows) === true) {
$id = 'Guest';
} else if (is_numeric($id) === true || empty($id) === true) {
} elseif (is_numeric($id) === true || empty($id) === true) {
$id = 'UnKnown';
foreach (['username', 'account', 'email', 'name', 'id'] as $key) {
if (isset($rows[$key]) === true) {
Expand Down
6 changes: 3 additions & 3 deletions src/Panels/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public static function highlight($sql, array $bindings = [], PDO $pdo = null)
$sql = preg_replace_callback('#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])('.static::KEYWORDS1.')(?=[\\s,)])|(?<=[\\s,(=])('.static::KEYWORDS2.')(?=[\\s,)=])#is', function ($matches) {
if (! empty($matches[1])) { // comment
return '<em style="color:gray">'.$matches[1].'</em>';
} else if (! empty($matches[2])) { // error
} elseif (! empty($matches[2])) { // error
return '<strong style="color:red">'.$matches[2].'</strong>';
} else if (! empty($matches[3])) { // most important keywords
} elseif (! empty($matches[3])) { // most important keywords
return '<strong style="color:blue; text-transform: uppercase;">'.$matches[3].'</strong>';
} else if (! empty($matches[4])) { // other keywords
} elseif (! empty($matches[4])) { // other keywords
return '<strong style="color:green">'.$matches[4].'</strong>';
}
}, $sql);
Expand Down
6 changes: 3 additions & 3 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class Template
/**
* @var array
*/
protected $attributes = [];
private $attributes = [];
/**
* @var bool
*/
protected $minify = true;
private $minify = true;

/**
* setAttributes.
Expand Down Expand Up @@ -66,7 +66,7 @@ public function render($view)
* @param string $buffer
* @return string
*/
protected function min($buffer)
private function min($buffer)
{
return preg_replace(
['/<!--(.*)-->/Uis', '/[[:blank:]]+/'],
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Tracy
/**
* @var Bar
*/
protected $bar;
private $bar;

/**
* __construct.
Expand Down
Loading

0 comments on commit 7fae5c6

Please sign in to comment.