Skip to content

Commit

Permalink
Show View configs on debug collector
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Jan 30, 2022
1 parent b594e94 commit 47ffba6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
42 changes: 33 additions & 9 deletions src/Debug/ViewCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Framework\MVC\Debug;

use Framework\Debug\Collector;
use Framework\MVC\View;

/**
* Class ViewCollector.
Expand All @@ -19,11 +18,19 @@
*/
class ViewCollector extends Collector
{
protected View $view;
/**
* @var array<string,mixed>
*/
protected array $config;

public function setView(View $view) : static
/**
* @param array<string,mixed> $config
*
* @return static
*/
public function setConfig(array $config) : static
{
$this->view = $view;
$this->config = $config;
return $this;
}

Expand All @@ -44,13 +51,30 @@ public function getActivities() : array

public function getContents() : string
{
if ( ! isset($this->view)) {
return '<p>A View instance has not been set on this collector.</p>';
}
\ob_start(); ?>
\ob_start();
if (isset($this->config['baseDir'])): ?>
<p><strong>Base Directory:</strong> <?= \htmlentities($this->config['baseDir']) ?></p>
<?php
endif;
if (isset($this->config['extension'])): ?>
<p><strong>Extension:</strong> <?= \htmlentities($this->config['extension']) ?></p>
<?php
endif;
if (isset($this->config['layoutPrefix']) && $this->config['layoutPrefix'] !== ''): ?>
<p><strong>Layout Prefix:</strong> <?= \htmlentities($this->config['layoutPrefix']) ?>
</p>
<?php
endif;
if (isset($this->config['includePrefix']) && $this->config['includePrefix'] !== ''): ?>
<p><strong>Include Prefix:</strong> <?= \htmlentities($this->config['includePrefix']) ?>
</p>
<?php
endif ?>
<h1>Rendered Views</h1>
<?php
echo $this->renderRenderedViews();
echo $this->hasData()
? $this->renderRenderedViews()
: '<p>No view has been rendered.</p>';
return \ob_get_clean(); // @phpstan-ignore-line
}

Expand Down
7 changes: 6 additions & 1 deletion src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,12 @@ public function includeWithoutPrefix(string $view, array $variables = []) : stat
public function setDebugCollector(ViewCollector $debugCollector) : static
{
$this->debugCollector = $debugCollector;
$this->debugCollector->setView($this);
$this->debugCollector->setConfig([
'baseDir' => $this->getBaseDir(),
'extension' => $this->getExtension(),
'layoutPrefix' => $this->getLayoutPrefix(),
'includePrefix' => $this->getIncludePrefix(),
]);
return $this;
}
}

0 comments on commit 47ffba6

Please sign in to comment.