From f89cfebf000059cb4d434aada9d27feb945f4b47 Mon Sep 17 00:00:00 2001 From: Rostunov Sergey Date: Sun, 12 Dec 2021 20:00:17 +0300 Subject: [PATCH 1/4] Fix compatibility of Twig 3 --- src/RunTracy/Helpers/TwigPanel.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/RunTracy/Helpers/TwigPanel.php b/src/RunTracy/Helpers/TwigPanel.php index 6d22620..076986d 100644 --- a/src/RunTracy/Helpers/TwigPanel.php +++ b/src/RunTracy/Helpers/TwigPanel.php @@ -28,7 +28,13 @@ class TwigPanel implements IBarPanel public function __construct($data = null) { $this->data = $data; - $this->dumper = new \Twig_Profiler_Dumper_Html(); + + if (class_exists('\Twig_Profiler_Dumper_Html', false)) { + $dumper = new \Twig_Profiler_Dumper_Html(); + } else { + $dumper = new \Twig\Profiler\Dumper\HtmlDumper(); + } + $this->dumper = $dumper; } public function getTab() From 226e579fafeacd2dc4d0a12774cd5622a780c284 Mon Sep 17 00:00:00 2001 From: Rostunov Sergey Date: Sun, 12 Dec 2021 20:03:34 +0300 Subject: [PATCH 2/4] Fix compatibility of Twig 3 --- tests/RunTracy/Helpers/TwigPanelTest.php | 30 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/RunTracy/Helpers/TwigPanelTest.php b/tests/RunTracy/Helpers/TwigPanelTest.php index 27e466a..136c2ce 100644 --- a/tests/RunTracy/Helpers/TwigPanelTest.php +++ b/tests/RunTracy/Helpers/TwigPanelTest.php @@ -33,7 +33,12 @@ public function testTwigPanel() $c = $app->getContainer(); $c['twig_profile'] = function () { - return new \Twig_Profiler_Profile(); + if (class_exists('\Twig_Profiler_Profile', false)) { + $profile = new \Twig_Profiler_Profile(); + } else { + $profile = new \Twig\Profiler\Profile(); + } + return $profile; }; $view = new \Slim\Views\Twig( @@ -42,14 +47,31 @@ public function testTwigPanel() ); // Add extensions $view->addExtension(new \Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri())); - $view->addExtension(new \Twig_Extension_Profiler($c['twig_profile'])); - $view->addExtension(new \Twig_Extension_Debug()); + + if (class_exists('\Twig_Extension_Profiler', false)) { + $profileExtention = new \Twig_Extension_Profiler($c['twig_profile']); + } else { + $profileExtention = new \Twig\Extension\ProfilerExtension($c['twig_profile']); + } + $view->addExtension($profileExtention); + + if (class_exists('\Twig_Extension_Debug', false)) { + $debugExtention = new \Twig_Extension_Debug(); + } else { + $debugExtention = new \Twig\Extension\DebugExtension(); + } + $view->addExtension($debugExtention); $this->assertInstanceOf('\Slim\App', $app); $this->assertInstanceOf('\Slim\Container', $c); - $this->assertInstanceOf('\Twig_Profiler_Profile', $c['twig_profile']); $this->assertInstanceOf('\Slim\Views\Twig', $view); + if (class_exists('\Twig_Profiler_Profile', false)) { + $this->assertInstanceOf('\Twig_Profiler_Profile', $c['twig_profile']); + } else { + $this->assertInstanceOf('\Twig\Extension\ProfilerExtension', $c['twig_profile']); + } + $panel = new \RunTracy\Helpers\TwigPanel($c['twig_profile']); $this->assertInstanceOf('\Tracy\IBarPanel', $panel); From 07cb973342bc76df7067c517d7db6f650abbf810 Mon Sep 17 00:00:00 2001 From: Rostunov Sergey Date: Sun, 12 Dec 2021 20:15:59 +0300 Subject: [PATCH 3/4] Fix compatibility of Twig 3 --- src/RunTracy/Helpers/ConsolePanel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RunTracy/Helpers/ConsolePanel.php b/src/RunTracy/Helpers/ConsolePanel.php index 83a6653..445ab90 100644 --- a/src/RunTracy/Helpers/ConsolePanel.php +++ b/src/RunTracy/Helpers/ConsolePanel.php @@ -87,9 +87,9 @@ function blinker() { public function getPanel() { - $this->noLogin = $this->cfg['ConsoleNoLogin']; - $this->terminalJs = $this->cfg['ConsoleTerminalJs']; - $this->terminalCss = $this->cfg['ConsoleTerminalCss']; + $this->noLogin = isset($this->cfg['ConsoleNoLogin']) ? $this->cfg['ConsoleNoLogin'] : null; + $this->terminalJs = isset($this->cfg['ConsoleTerminalJs']) ? $this->cfg['ConsoleTerminalJs'] : null; + $this->terminalCss = isset($this->cfg['ConsoleTerminalCss']) ? $this->cfg['ConsoleTerminalCss'] : null; ob_start(); require __DIR__ .'../../Templates/ConsolePanel.phtml'; From 646426f246b9eb4243528041a43b14c8274b9255 Mon Sep 17 00:00:00 2001 From: Rostunov Sergey Date: Sun, 12 Dec 2021 20:36:23 +0300 Subject: [PATCH 4/4] Fix compatibility of Twig 3 --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b7446d..ec8bb2c 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ $ composer require illuminate/database **2.2** add to your dependencies (Twig, Twig_Profiler) and/or Eloquent ORM like: ```php -// Twig +// Twig 1 $c['twig_profile'] = function () { return new Twig_Profiler_Profile(); }; @@ -71,6 +71,14 @@ $c['view'] = function ($c) { return $view; }; +// Twig 3 +$c['twig_profile'] = function () { + return new \Twig\Profiler\Profile(); +}; +... +$view->addExtension(new \Twig\Extension\ProfilerExtension($c['twig_profile'])); +$view->addExtension(new \Twig\Extension\DebugExtension()); + // Register Eloquent single connection $capsule = new \Illuminate\Database\Capsule\Manager; $capsule->addConnection($cfg['settings']['db']['connections']['mysql']);