Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/App/Stages/InitDebuggerStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@
namespace Quantum\App\Stages;

use Quantum\App\Contracts\BootStageInterface;
use Quantum\Di\Exceptions\DiException;
use Quantum\Debugger\Debugger;
use Quantum\App\AppContext;
use ReflectionException;
use Quantum\Di\Di;

/**
* Class InitDebuggerStage
* @package Quantum\App
*/
class InitDebuggerStage implements BootStageInterface
{
/**
* @throws DiException|ReflectionException
*/
public function process(AppContext $context): void
{
if (!Di::isRegistered(Debugger::class)) {
Di::register(Debugger::class);
}

Di::get(Debugger::class)->initStore();
debugbar()->initStore();
}
}
6 changes: 3 additions & 3 deletions src/App/Traits/WebAppTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ private function loadLanguage(): void
*/
private function logDebugInfo(): void
{
$debugger = Di::get(Debugger::class);
$debugbar = debugbar();

if ($debugger->isEnabled()) {
$debugger->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
if ($debugbar->isEnabled()) {
$debugbar->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
}
}

Expand Down
18 changes: 1 addition & 17 deletions src/Logger/Adapters/MessageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,19 @@
namespace Quantum\Logger\Adapters;

use Quantum\Logger\Contracts\ReportableInterface;
use Quantum\Di\Exceptions\DiException;
use DebugBar\DebugBarException;
use Quantum\Debugger\Debugger;
use ReflectionException;
use Quantum\Di\Di;

/**
* Class MessageAdapter
* @package Quantum\Logger
*/
class MessageAdapter implements ReportableInterface
{
/**
* @param array<string, mixed>|null $context
* @throws DebugBarException
*/

/**
* @throws DiException|ReflectionException
*/
public function report(string $level, string $message, ?array $context = []): void
{
$tab = $context['tab'] ?? Debugger::MESSAGES;

if (!Di::isRegistered(Debugger::class)) {
Di::register(Debugger::class);
}

$debugger = Di::get(Debugger::class);
$debugger = debugbar();

if ($debugger->isEnabled()) {
$debugger->addToStoreCell($tab, $level, $message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>
<body>

<main><?php echo view() ?></main>
<main><?= view()->getContent() ?></main>

<?= debugbar()->render() ?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace {{MODULE_NAMESPACE}}\Controllers;

use Quantum\View\Factories\ViewFactory;
use Quantum\Asset\Asset;
use Quantum\View\QtView;
use Quantum\View\View;

/**
* Class BaseController
Expand All @@ -26,9 +26,9 @@ abstract class BaseController
{

/**
* @var QtView
* @var View
*/
protected QtView $view;
protected View $view;

public function __before()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body>
<header><?php echo partial('partials/navbar') ?></header>

<main><?php echo view() ?></main>
<main><?= view()->getContent() ?></main>

<footer class="page-footer"><?php echo partial('partials/footer') ?></footer>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Modules\Toolkit\Controllers;

use Quantum\View\Factories\ViewFactory;
use Quantum\Asset\Asset;
use Quantum\View\QtView;
use Quantum\View\View;

/**
* Class BaseController
Expand All @@ -40,9 +40,9 @@ class BaseController
protected const CURRENT_PAGE = 1;

/**
* @var QtView
* @var View
*/
protected QtView $view;
protected View $view;

/**
* Works before an action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<body>

<main>
<?php echo view() ?>
<?= view()->getContent() ?>
</main>

<?php assets("js") ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<main>
<div id="toolkit-content">
<?php echo view() ?>
<?= view()->getContent() ?>
</div>
</main>

Expand Down
15 changes: 7 additions & 8 deletions src/View/Factories/ViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
use Quantum\App\Exceptions\BaseException;
use Quantum\Di\Exceptions\DiException;
use Quantum\ResourceCache\ViewCache;
use Quantum\Debugger\Debugger;
use Quantum\View\QtView;
use ReflectionException;
use Quantum\View\View;
use Quantum\Di\Di;

/**
* Class ViewFactory
* @package Quantum\View
* @mixin QtView
* @mixin View
*/
class ViewFactory
{
private ?QtView $instance = null;
private ?View $instance = null;

/**
* @throws ConfigException|BaseException|DiException|ReflectionException
*/
public static function get(): QtView
public static function get(): View
{
if (!Di::isRegistered(self::class)) {
Di::register(self::class);
Expand All @@ -50,17 +49,17 @@ public static function get(): QtView
/**
* @throws ConfigException|BaseException|DiException|ReflectionException
*/
public function resolve(): QtView
public function resolve(): View
{
if ($this->instance === null) {
if (!Di::isRegistered(ViewCache::class)) {
Di::register(ViewCache::class);
}

$this->instance = new QtView(
$this->instance = new View(
RendererFactory::get(),
asset(),
Di::get(Debugger::class),
debugbar(),
Di::get(ViewCache::class)
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/View/Helpers/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

use League\CommonMark\Exception\CommonMarkException;
use Quantum\Config\Exceptions\ConfigException;
use Quantum\View\Exceptions\ViewException;
use League\CommonMark\CommonMarkConverter;
use Quantum\App\Exceptions\BaseException;
use Quantum\View\Factories\ViewFactory;
use Quantum\Di\Exceptions\DiException;
use Quantum\View\RawParam;
use Quantum\View\View;

/**
* Rendered view
* @throws ViewException|ConfigException|DiException|BaseException|ReflectionException
* Gets the View instance
* @throws ConfigException|DiException|BaseException|ReflectionException
*/
function view(): ?string
function view(): View
{
return ViewFactory::get()->getView();
return ViewFactory::get();
}

/**
Expand All @@ -39,7 +39,7 @@ function view(): ?string
*/
function partial(string $partial, array $args = []): string
{
return ViewFactory::get()->renderPartial($partial, $args);
return view()->renderPartial($partial, $args);
}

/**
Expand All @@ -52,7 +52,7 @@ function partial(string $partial, array $args = []): string
*/
function view_param(string $key)
{
return ViewFactory::get()->getParam($key);
return view()->getParam($key);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/View/QtView.php → src/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
use Psr\Log\LogLevel;

/**
* Class QtView
* Class View
* @package Quantum\View
*/
class QtView
class View
{
private Renderer $renderer;

Expand Down Expand Up @@ -221,10 +221,10 @@ public function renderPartial(string $viewFile, array $params = []): string
}

/**
* Gets the rendered view.
* Gets the rendered view content.
* @throws ViewException
*/
public function getView(): ?string
public function getContent(): ?string
{
if ($this->viewContent === null) {
throw ViewException::viewNotRendered();
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/View/Factories/ViewFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Quantum\View\Factories\ViewFactory;
use Quantum\Tests\Unit\AppTestCase;
use Quantum\View\QtView;
use Quantum\View\View;
use Quantum\Di\Di;

class ViewFactoryTest extends AppTestCase
Expand All @@ -26,7 +26,7 @@ public function setUp(): void

public function testGetInstance(): void
{
$this->assertInstanceOf(QtView::class, ViewFactory::get());
$this->assertInstanceOf(View::class, ViewFactory::get());
}

public function testResolveReturnsSameInstance(): void
Expand Down
13 changes: 9 additions & 4 deletions tests/Unit/View/Helpers/ViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Quantum\Router\MatchedRoute;
use Quantum\Router\Route;
use Quantum\Tests\Unit\AppTestCase;
use Quantum\View\QtView;
use Quantum\View\View;

class ViewHelperTest extends AppTestCase
{
private QtView $view;
private View $view;

public function setUp(): void
{
Expand All @@ -36,13 +36,18 @@ public function tearDown(): void
$this->view->setLayout(null);
}

public function testView(): void
public function testViewReturnsInstance(): void
{
$this->assertInstanceOf(View::class, view());
}

public function testViewGetContent(): void
{
$this->view->setLayout('layout');

$this->view->render('index');

$this->assertEquals('<p>Hello World, this is rendered html view</p>', view());
$this->assertEquals('<p>Hello World, this is rendered html view</p>', view()->getContent());
}

public function testPartial(): void
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/View/QtViewTest.php → tests/Unit/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Quantum\View\Factories\ViewFactory;
use Quantum\Tests\Unit\AppTestCase;
use Quantum\Router\MatchedRoute;
use Quantum\View\QtView;
use Quantum\View\RawParam;
use Quantum\Router\Route;
use Quantum\View\View;
use Quantum\Di\Di;

class QtViewTest extends AppTestCase
class ViewTest extends AppTestCase
{
private QtView $view;
private View $view;

public function setUp(): void
{
Expand Down Expand Up @@ -126,13 +126,13 @@ public function testRenderWithData(): void

$this->view->render('index', ['name' => 'Lorem Ipsum']);

$this->assertEquals('<p>Hello Lorem Ipsum, this is rendered html view</p>', $this->view->getView());
$this->assertEquals('<p>Hello Lorem Ipsum, this is rendered html view</p>', $this->view->getContent());

$this->view->setParam('name', 'dolor sit amet');

$this->view->render('index');

$this->assertEquals('<p>Hello dolor sit amet, this is rendered html view</p>', $this->view->getView());
$this->assertEquals('<p>Hello dolor sit amet, this is rendered html view</p>', $this->view->getContent());
}

public function testRenderWithEscapedHtmlData(): void
Expand All @@ -143,7 +143,7 @@ public function testRenderWithEscapedHtmlData(): void

$this->view->render('post');

$this->assertEquals('&lt;h1&gt;Hello&lt;/h1&gt;', $this->view->getView());
$this->assertEquals('&lt;h1&gt;Hello&lt;/h1&gt;', $this->view->getContent());
}

public function testRenderWithUnEscapedHtmlData(): void
Expand All @@ -154,7 +154,7 @@ public function testRenderWithUnEscapedHtmlData(): void

$this->view->render('post');

$this->assertEquals('<h1>Hello</h1>', $this->view->getView());
$this->assertEquals('<h1>Hello</h1>', $this->view->getContent());
}

public function testRenderPartial(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/_root/modules/Test/Views/layout.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head></head>
<body>
<?php echo view() ?>
<?= view()->getContent() ?>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/_root/modules/Test/Views/layout.twig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head></head>
<body>
{{ view() }}
{{ view().getContent() }}
</body>
</html>
Loading