Skip to content

Commit

Permalink
Merge pull request #7172 from kenjis/fix-debugbar-collectors-viewer
Browse files Browse the repository at this point in the history
fix: cannot create shared View instance when using debugbar
  • Loading branch information
kenjis authored Jan 29, 2023
2 parents 8c8ed6d + 4d73ea1 commit b302f15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ parameters:
count: 13
path: system/Database/SQLSRV/Forge.php

-
message: "#^Call to an undefined method CodeIgniter\\\\View\\\\RendererInterface\\:\\:getPerformanceData\\(\\)\\.$#"
count: 1
path: system/Debug/Toolbar/Collectors/Events.php

-
message: "#^Property CodeIgniter\\\\Log\\\\Logger\\:\\:\\$logCache \\(array\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
Expand Down
28 changes: 5 additions & 23 deletions system/Debug/Toolbar/Collectors/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

namespace CodeIgniter\Debug\Toolbar\Collectors;

use CodeIgniter\View\RendererInterface;
use Config\Services;

/**
* Views collector
* Events collector
*/
class Events extends BaseCollector
{
Expand All @@ -25,7 +22,7 @@ class Events extends BaseCollector
*
* @var bool
*/
protected $hasTimeline = false;
protected $hasTimeline = true;

/**
* Whether this collector needs to display
Expand All @@ -51,21 +48,6 @@ class Events extends BaseCollector
*/
protected $title = 'Events';

/**
* Instance of the Renderer service
*
* @var RendererInterface
*/
protected $viewer;

/**
* Constructor.
*/
public function __construct()
{
$this->viewer = Services::renderer();
}

/**
* Child classes should implement this to return the timeline data
* formatted for correct usage.
Expand All @@ -74,12 +56,12 @@ protected function formatTimelineData(): array
{
$data = [];

$rows = $this->viewer->getPerformanceData();
$rows = \CodeIgniter\Events\Events::getPerformanceLogs();

foreach ($rows as $info) {
$data[] = [
'name' => 'View: ' . $info['view'],
'component' => 'Views',
'name' => 'Event: ' . $info['event'],
'component' => 'Events',
'start' => $info['start'],
'duration' => $info['end'] - $info['start'],
];
Expand Down
18 changes: 10 additions & 8 deletions system/Debug/Toolbar/Collectors/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Views extends BaseCollector
protected $title = 'Views';

/**
* Instance of the Renderer service
* Instance of the shared Renderer service
*
* @var RendererInterface
* @var RendererInterface|null
*/
protected $viewer;

Expand All @@ -73,12 +73,9 @@ class Views extends BaseCollector
*/
protected $views = [];

/**
* Constructor.
*/
public function __construct()
private function initViewer(): void
{
$this->viewer = Services::renderer();
$this->viewer ??= Services::renderer();
}

/**
Expand All @@ -87,6 +84,8 @@ public function __construct()
*/
protected function formatTimelineData(): array
{
$this->initViewer();

$data = [];

$rows = $this->viewer->getPerformanceData();
Expand Down Expand Up @@ -121,8 +120,9 @@ protected function formatTimelineData(): array
*/
public function getVarData(): array
{
return [
$this->initViewer();

return [
'View Data' => $this->viewer->getData(),
];
}
Expand All @@ -132,6 +132,8 @@ public function getVarData(): array
*/
public function getBadgeValue(): int
{
$this->initViewer();

return count($this->viewer->getPerformanceData());
}

Expand Down

0 comments on commit b302f15

Please sign in to comment.