Skip to content

Commit

Permalink
Merge pull request #18 from MartinMystikJonas/nette-2.2-compatibility
Browse files Browse the repository at this point in the history
Fixed compatibility with Nette 2.2
  • Loading branch information
enumag committed May 16, 2014
2 parents 435ff80 + 54c78b7 commit 6ac4222
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/Kdyby/SessionPanel/DI/SessionPanelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class_alias('Nette\Utils\PhpGenerator\ClassType', 'Nette\PhpGenerator\ClassType'
class_alias('Nette\Config\Configurator', 'Nette\Configurator');
}



/**
* @author Jáchym Toušek <[email protected]>
*/
Expand All @@ -40,10 +42,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$builder = $this->getContainerBuilder();
if ($builder->parameters['debugMode']) {
$class->methods['initialize']->addBody($builder->formatPhp(
'Nette\Diagnostics\Debugger::' . (method_exists('Nette\Diagnostics\Debugger', 'getBar') ? 'getBar()' : '$bar') . '->addPanel(?);',
Nette\DI\Compiler::filterArguments(array(new Nette\DI\Statement($this->prefix('@panel'))))
));
$class->methods['initialize']->addBody(
'Kdyby\SessionPanel\Diagnostics\SessionPanel::register($this->getService(?));',
array($this->prefix('panel'))
);
}
}

Expand Down
87 changes: 78 additions & 9 deletions src/Kdyby/SessionPanel/Diagnostics/SessionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
use Nette;
use Nette\Http\IRequest;
use Nette\Iterators\Mapper;
use Tracy;



if (!class_exists('Tracy\Debugger')) {
class_alias('Nette\Diagnostics\Debugger', 'Tracy\Debugger');
}

if (!class_exists('Tracy\Dumper') && class_exists('Nette\Diagnostics\Dumper')) {
class_alias('Nette\Diagnostics\Dumper', 'Tracy\Dumper');
}

if (!class_exists('Tracy\Bar')) {
class_alias('Nette\Diagnostics\Bar', 'Tracy\Bar');
class_alias('Nette\Diagnostics\BlueScreen', 'Tracy\BlueScreen');
class_alias('Nette\Diagnostics\Helpers', 'Tracy\Helpers');
class_alias('Nette\Diagnostics\IBarPanel', 'Tracy\IBarPanel');
}

if (!class_exists('Latte\Runtime\Filters')) {
class_alias('Nette\Templating\Helpers', 'Latte\Runtime\Filters');
}

if (!class_exists('Nette\Utils\DateTime')) {
class_alias('Nette\DateTime', 'Nette\Utils\DateTime');
}



Expand All @@ -14,7 +40,7 @@
* @author Pavel Železný <[email protected]>
* @author Filip Procházka <[email protected]>
*/
class SessionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
class SessionPanel extends Nette\Object implements Tracy\IBarPanel
{

const SIGNAL = 'nette-session-panel-delete-session';
Expand Down Expand Up @@ -85,9 +111,9 @@ public function getTab()
{
return self::render(__DIR__ . '/templates/tab.phtml', array(
'src' => function ($file) {
return Nette\Templating\Helpers::dataStream(file_get_contents($file));
return \Latte\Runtime\Filters::dataStream(file_get_contents($file));
},
'esc' => callback('Nette\Templating\Helpers::escapeHtml'),
'esc' => callback('Latte\Runtime\Filters::escapeHtml'),
));
}

Expand All @@ -104,8 +130,8 @@ public function getPanel()
'time' => callback(get_called_class() . '::time'),
'esc' => callback('Nette\Templating\Helpers::escapeHtml'),
'click' => callback(function ($variable) {
if (class_exists('Nette\Diagnostics\Dumper')) {
return Nette\Diagnostics\Dumper::toHtml($variable, array(Nette\Diagnostics\Dumper::COLLAPSE => TRUE));
if (class_exists('Tracy\Dumper')) {
return Tracy\Dumper::toHtml($variable, array(Tracy\Dumper::COLLAPSE => TRUE));
} else {
return Nette\Diagnostics\Helpers::clickableDump($variable, TRUE);
}
Expand Down Expand Up @@ -202,9 +228,15 @@ protected function createNetteSessionIterator()
*/
public static function render($file, $vars)
{
ob_start();
Nette\Utils\LimitedScope::load(str_replace('/', DIRECTORY_SEPARATOR, $file), $vars);
return ob_get_clean();
return call_user_func(function() {
ob_start();
foreach (func_get_arg(1) as $__k => $__v) {
$$__k = $__v;
}
unset($__k, $__v);
require func_get_arg(0);
return ob_get_clean();
}, $file, $vars);
}


Expand All @@ -218,12 +250,49 @@ public static function time($seconds)
static $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
static $lengths = array("60", "60", "24", "7", "4.35", "12", "10");

$difference = $seconds > Nette\DateTime::YEAR ? time() - $seconds : $seconds;
$difference = $seconds > Nette\Utils\DateTime::YEAR ? time() - $seconds : $seconds;
for ($j = 0; $difference >= $lengths[$j]; $j++) {
$difference /= $lengths[$j];
}
$multiply = ($difference = round($difference)) != 1;
return "$difference {$periods[$j]}" . ($multiply ? 's' : '');
}



/****************** Registration *********************/



/**
* Registers panel to debugger
*
* @param \Tracy\Bar $bar
*/
public function registerBarPanel(Tracy\Bar $bar)
{
$bar->addPanel($this);
}


/**
* @return Panel
*/
public static function register(SessionPanel $panel)
{
$panel->registerBarPanel(static::getDebuggerBar());
return $panel;
}



/**
* @return Bar
*/
private static function getDebuggerBar()
{
return method_exists('Tracy\Debugger', 'getBar') ? Tracy\Debugger::getBar() : Tracy\Debugger::$bar;
}


}

0 comments on commit 6ac4222

Please sign in to comment.