diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4c66427..d086353 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,8 +8,8 @@ jobs: fail-fast: false matrix: php: - - "7.4" - "8.1" + - "8.2" steps: - name: "Checkout" uses: "actions/checkout@v3" diff --git a/Helper/Injector.php b/Helper/Injector.php index e0d4ed0..c54d249 100644 --- a/Helper/Injector.php +++ b/Helper/Injector.php @@ -9,6 +9,9 @@ class Injector { + private const TEMPLATE_TOOLBAR = 'ClawRock_Debug::profiler/toolbar/js.phtml'; + private const TEMPLATE_BLOCK = 'ClawRock_Debug::profiler/js.phtml'; + private \Magento\Framework\View\LayoutInterface $layout; private \ClawRock\Debug\Model\View\Toolbar $viewModel; @@ -27,16 +30,29 @@ public function inject(Request $request, Response $response, ?string $token = nu if (false !== $pos) { /** @var \Magento\Framework\View\Element\Template $toolbarBlock */ - $toolbarBlock = $this->layout->createBlock(Template::class, 'debug.toolbar'); - $toolbarBlock->setTemplate('ClawRock_Debug::profiler/toolbar/js.phtml')->setData([ - 'view_model' => $this->viewModel, - 'token' => $token, - 'request' => $request, - ]); + $toolbarBlock = $this->layout->createBlock( + Template::class, + 'debug.toolbar', + [ + 'data' => [ + 'template' => self::TEMPLATE_TOOLBAR, + 'view_model' => $this->viewModel, + 'token' => $token, + 'request' => $request, + ], + ] + ); /** @var \Magento\Framework\View\Element\Template $jsBlock */ - $jsBlock = $this->layout->createBlock(Template::class, 'debug.profiler.js'); - $jsBlock->setTemplate('ClawRock_Debug::profiler/js.phtml'); + $jsBlock = $this->layout->createBlock( + Template::class, + 'debug.profiler.js', + [ + 'data' => [ + 'template' => self::TEMPLATE_BLOCK, + ], + ] + ); $toolbarBlock->setChild('debug_profiler_js', $jsBlock); diff --git a/Model/Info/RequestInfo.php b/Model/Info/RequestInfo.php index 6cd479f..43ddb0c 100644 --- a/Model/Info/RequestInfo.php +++ b/Model/Info/RequestInfo.php @@ -134,7 +134,7 @@ public function getStatusCode(): int */ public function getSessionAttributes(): array { - return session_status() ? $_SESSION : []; // phpcs:ignore Magento2.Security.Superglobal.SuperglobalUsageError + return $_SESSION ?? []; // phpcs:ignore Magento2.Security.Superglobal.SuperglobalUsageError } public function getPathInfo(): string diff --git a/Model/View/Renderer/LayoutGraphRenderer.php b/Model/View/Renderer/LayoutGraphRenderer.php index d58bf77..2645d3a 100644 --- a/Model/View/Renderer/LayoutGraphRenderer.php +++ b/Model/View/Renderer/LayoutGraphRenderer.php @@ -34,14 +34,19 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + 'clawrock_layout_graph_renderer', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'nodes' => $this->createNodes(), + 'layout_node_renderer' => $this->layoutNodeRendererFactory, + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData([ - 'nodes' => $this->createNodes(), - 'layout_node_renderer' => $this->layoutNodeRendererFactory, - ]) - ->toHtml(); + return $block->toHtml(); } private function createNodes(): array diff --git a/Model/View/Renderer/LayoutNodeRenderer.php b/Model/View/Renderer/LayoutNodeRenderer.php index 269038e..0ed288f 100644 --- a/Model/View/Renderer/LayoutNodeRenderer.php +++ b/Model/View/Renderer/LayoutNodeRenderer.php @@ -29,14 +29,19 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'node' => $this->node, + 'formatter' => $this->formatter, + 'layout_node_renderer' => $this->layoutNodeRendererFactory, + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData([ - 'node' => $this->node, - 'formatter' => $this->formatter, - 'layout_node_renderer' => $this->layoutNodeRendererFactory, - ]) - ->toHtml(); + return $block->toHtml(); } } diff --git a/Model/View/Renderer/ParametersRenderer.php b/Model/View/Renderer/ParametersRenderer.php index 2a4cdb1..8b14c65 100644 --- a/Model/View/Renderer/ParametersRenderer.php +++ b/Model/View/Renderer/ParametersRenderer.php @@ -26,11 +26,18 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'parameters' => $this->parameters, + 'var_renderer' => $this->varRenderer, + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData('parameters', $this->parameters) - ->setData('var_renderer', $this->varRenderer) - ->toHtml(); + return $block->toHtml(); } } diff --git a/Model/View/Renderer/QueryListRenderer.php b/Model/View/Renderer/QueryListRenderer.php index 742570a..b0d628b 100644 --- a/Model/View/Renderer/QueryListRenderer.php +++ b/Model/View/Renderer/QueryListRenderer.php @@ -33,15 +33,20 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'queries' => $this->queries, + 'query_renderer' => $this->queryRendererFactory, + 'prefix' => $this->mathRandom->getUniqueHash(), + 'formatter' => $this->formatter, + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData([ - 'queries' => $this->queries, - 'query_renderer' => $this->queryRendererFactory, - 'prefix' => $this->mathRandom->getUniqueHash(), - 'formatter' => $this->formatter, - ]) - ->toHtml(); + return $block->toHtml(); } } diff --git a/Model/View/Renderer/QueryRenderer.php b/Model/View/Renderer/QueryRenderer.php index a603f72..c88809f 100644 --- a/Model/View/Renderer/QueryRenderer.php +++ b/Model/View/Renderer/QueryRenderer.php @@ -32,22 +32,27 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'query' => $this->query, + 'highlighted_query' => $this->databaseHelper->highlightQuery($this->query->getQuery()), + 'formatted_query' => $this->databaseHelper->formatQuery($this->query->getQuery()), + 'runnable_query' => $this->databaseHelper->highlightQuery( + $this->databaseHelper->replaceQueryParameters( + $this->query->getQuery(), + $this->query->getQueryParams() + ) + ), + 'var_renderer' => $this->varRenderer, + 'uniq_id' => $this->mathRandom->getUniqueHash(), + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData([ - 'query' => $this->query, - 'highlighted_query' => $this->databaseHelper->highlightQuery($this->query->getQuery()), - 'formatted_query' => $this->databaseHelper->formatQuery($this->query->getQuery()), - 'runnable_query' => $this->databaseHelper->highlightQuery( - $this->databaseHelper->replaceQueryParameters( - $this->query->getQuery(), - $this->query->getQueryParams() - ) - ), - 'var_renderer' => $this->varRenderer, - 'uniq_id' => $this->mathRandom->getUniqueHash(), - ]) - ->toHtml(); + return $block->toHtml(); } } diff --git a/Model/View/Renderer/RedirectRenderer.php b/Model/View/Renderer/RedirectRenderer.php index 04be772..deb0af7 100644 --- a/Model/View/Renderer/RedirectRenderer.php +++ b/Model/View/Renderer/RedirectRenderer.php @@ -37,10 +37,17 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); - - return $block->setTemplate(self::TEMPLATE) - ->setProfilerUrl($this->url->getProfilerUrl($this->redirect->getToken())) + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + ], + ] + ); + + return $block->setProfilerUrl($this->url->getProfilerUrl($this->redirect->getToken())) ->setRedirect($this->redirect) ->toHtml(); } diff --git a/Model/View/Renderer/TableRenderer.php b/Model/View/Renderer/TableRenderer.php index e9a6caa..0070392 100644 --- a/Model/View/Renderer/TableRenderer.php +++ b/Model/View/Renderer/TableRenderer.php @@ -29,14 +29,21 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'items' => $this->items, + 'labels' => $this->labels, + 'var_renderer' => $this->varRenderer, + 'key_label' => $this->labels[0] ?? 'Key', + 'value_label' => $this->labels[1] ?? 'Value', + ], + ] + ); - return $block->setTemplate(self::TEMPLATE) - ->setData('items', $this->items) - ->setData('labels', $this->labels) - ->setData('var_renderer', $this->varRenderer) - ->setData('key_label', $this->labels[0] ?? 'Key') - ->setData('value_label', $this->labels[1] ?? 'Value') - ->toHtml(); + return $block->toHtml(); } } diff --git a/Model/View/Renderer/TraceCallRenderer.php b/Model/View/Renderer/TraceCallRenderer.php index 858e2e4..bba3fc3 100644 --- a/Model/View/Renderer/TraceCallRenderer.php +++ b/Model/View/Renderer/TraceCallRenderer.php @@ -27,7 +27,15 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + ], + ] + ); foreach (self::CALL_INFO as $info) { if (isset($this->call[$info])) { @@ -38,7 +46,7 @@ public function render(): string $block->setFile($this->relativizePath($block->getFile())); } - return $block->setTemplate(self::TEMPLATE)->toHtml(); + return $block->toHtml(); } private function relativizePath(string $path): string diff --git a/Model/View/Renderer/TraceRenderer.php b/Model/View/Renderer/TraceRenderer.php index 655781d..1336ff1 100644 --- a/Model/View/Renderer/TraceRenderer.php +++ b/Model/View/Renderer/TraceRenderer.php @@ -28,13 +28,20 @@ public function __construct( public function render(): string { /** @var \Magento\Framework\View\Element\Template $block */ - $block = $this->layout->createBlock(Template::class); - - return $block->setTemplate(self::TEMPLATE) - ->setData('trace', $this->trace) - ->setData('trace_id', $this->id) - ->setData('trace_call_renderer', $this->traceCallRendererFactory) - ->toHtml(); + $block = $this->layout->createBlock( + Template::class, + '', + [ + 'data' => [ + 'template' => self::TEMPLATE, + 'trace' => $this->trace, + 'trace_id' => $this->id, + 'trace_call_renderer' => $this->traceCallRendererFactory, + ], + ] + ); + + return $block->toHtml(); } public function getId(): string diff --git a/Readme.md b/Readme.md index 73bc2eb..ed1ee21 100644 --- a/Readme.md +++ b/Readme.md @@ -16,8 +16,8 @@ Module for debugging Magento 2 performance. It works without overwriting any cor All settings have only default scope and config type pool is set to environment for better integration with `php bin/magento app:config:dump` ## Compatibility -* Magento 2.4 -* PHP 7.4, 8.1 +* Magento >= 2.4.4 +* PHP 8.1, 8.2 ## Profiler collectors - Ajax diff --git a/composer.json b/composer.json index 4724663..901ce24 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "AFL-3.0" ], "require": { - "php": ">=7.4", + "php": ">=8.1", "magento/framework": "~103.0", "magento/module-backend": "~102.0", "magento/module-developer": "^100.4", @@ -17,16 +17,16 @@ "symfony/stopwatch": "^2.8 || ^3.0 || ^4.0 || ^5.0" }, "require-dev": { - "bitexpert/phpstan-magento": "^0.28.0", + "bitexpert/phpstan-magento": "^0.30.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", "magento/magento-coding-standard": "*", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.9.1", - "phpstan/phpstan": "~1.9.0", + "phpstan/phpstan": "~1.10.0", "phpunit/phpunit": "~9.5.0", "sebastian/phpcpd": "^6.0.3", "slevomat/coding-standard": "~6.4.1", - "squizlabs/php_codesniffer": "~3.6.0", + "squizlabs/php_codesniffer": "~3.7.2", "phpstan/phpstan-phpunit": "^1.1.1" }, "repositories": [