Skip to content

Commit

Permalink
BlueScreen: added kick-ass bluescreen with validation details
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 25, 2018
1 parent f3db794 commit e7b701c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/DI/DebugPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Apitte\Debug\Negotiation\Transformer\DebugTransformer;
use Apitte\Debug\Schema\Serialization\DebugSchemaDecorator;
use Apitte\Debug\Tracy\BlueScreen\ApiBlueScreen;
use Apitte\Debug\Tracy\BlueScreen\ValidationBlueScreen;
use Apitte\Debug\Tracy\Panel\ApiPanel;
use Apitte\Negotiation\DI\NegotiationPlugin;
use Nette\DI\ContainerBuilder;
use Nette\PhpGenerator\ClassType;
use Tracy\Debugger;

class DebugPlugin extends AbstractPlugin
{
Expand Down Expand Up @@ -45,6 +47,10 @@ public function loadPluginConfiguration()
->setClass(ApiPanel::class);

$this->loadNegotiationDebugConfiguration();

// BueScreen - runtime
ApiBlueScreen::register(Debugger::getBlueScreen());
ValidationBlueScreen::register(Debugger::getBlueScreen());
}

/**
Expand Down Expand Up @@ -79,6 +85,7 @@ public function afterPluginCompile(ClassType $class)
$initialize = $class->getMethod('initialize');

$initialize->addBody('?::register($this->getService(?));', [ContainerBuilder::literal(ApiBlueScreen::class), 'tracy.blueScreen']);
$initialize->addBody('?::register($this->getService(?));', [ContainerBuilder::literal(ValidationBlueScreen::class), 'tracy.blueScreen']);

if ($config['debug'] === TRUE) {
$initialize->addBody('$this->getService(?)->addPanel($this->getByType(?));', ['tracy.bar', ApiPanel::class]);
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen/ApiBlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function register(BlueScreen $blueScreen)
*/
private static function renderTab(ApiException $e)
{
return 'Api';
return 'Apitte';
}

/**
Expand Down
53 changes: 53 additions & 0 deletions src/Tracy/BlueScreen/ValidationBlueScreen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Apitte\Debug\Tracy\BlueScreen;

use Apitte\Core\Exception\Logical\InvalidSchemaException;
use ReflectionClass;
use Tracy\BlueScreen;
use Tracy\Helpers;

final class ValidationBlueScreen
{

/**
* @param BlueScreen $blueScreen
* @return void
*/
public static function register(BlueScreen $blueScreen)
{
$blueScreen->addPanel(function ($e) {
if (!($e instanceof InvalidSchemaException)) return;

return [
'tab' => self::renderTab($e),
'panel' => self::renderPanel($e),
];
});
}

/**
* @param InvalidSchemaException $e
* @return string
*/
private static function renderTab(InvalidSchemaException $e)
{
return 'Apitte - Validation';
}

/**
* @param InvalidSchemaException $e
* @return mixed
*/
private static function renderPanel(InvalidSchemaException $e)
{
if (!$e->controller || !$e->method) return NULL;

$rf = new ReflectionClass($e->controller->getClass());
$rm = $rf->getMethod($e->method->getName());

return '<p><b>File:</b>' . Helpers::editorLink($rf->getFileName(), $rm->getStartLine()) . '</p>'
. BlueScreen::highlightFile($rf->getFileName(), $rm->getStartLine(), 20);
}

}

0 comments on commit e7b701c

Please sign in to comment.