Skip to content

Commit

Permalink
Merge branch 'master' into 2.1-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Dec 14, 2020
2 parents d7715fb + 8827831 commit 844dbf8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
5 changes: 2 additions & 3 deletions publish/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\View\Engine\NoneEngine;
use Hyperf\View\Mode;
use Hyperf\ViewEngine\HyperfViewEngine;

return [
'engine' => HyperfViewEngine::class,
'engine' => NoneEngine::class,
'mode' => Mode::SYNC,
'config' => [
'view_path' => BASE_PATH . '/storage/view/',
'cache_path' => BASE_PATH . '/runtime/view/',
'charset' => 'UTF-8',
],
];
57 changes: 57 additions & 0 deletions src/Engine/NoneEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\View\Engine;

class NoneEngine implements EngineInterface
{
public function render($template, $data, $config): string
{
return <<<'HTML'
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hyperf</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Hyperf</h1>
<p>Hyperf is an extremely performant and flexible PHP CLI framework based on Swoole 4.5+, powered by the
state-of-the-art coroutine server and a large number of battle-tested components. Aside from the decisive
benchmark outmatching against PHP-FPM frameworks, Hyperf also distinct itself by its focus on flexibility
and composability. Hyperf ships with an AOP-enabling dependency injector to ensure components and classes
are pluggable and meta programmable. All of its core components strictly follow the PSR standards and thus
can be used in other frameworks.</p>
<p><a class="btn btn-primary btn-lg" href="https://hyperf.wiki/" role="button">Learn more</a></p>
<p>This view engine is not available, please use engines below.</p>
<ul class="list-group">
<li class="list-group-item"><a href="https://github.com/hyperf/view-engine">hyperf/view-engine</a></li>
<li class="list-group-item"><a href="https://github.com/duncan3dc/blade">duncan3dc/blade</a></li>
<li class="list-group-item"><a href="https://github.com/smarty-php/smarty">smarty/smarty</a></li>
<li class="list-group-item"><a href="https://github.com/twigphp/Twig">twig/twig</a></li>
<li class="list-group-item"><a href="https://github.com/thephpleague/plates">league/plates</a></li>
<li class="list-group-item"><a href="https://github.com/sy-records/think-template">sy-records/think-template</a></li>
</ul>
</div>
</div>
</body>
</html>
HTML;
}
}
4 changes: 2 additions & 2 deletions src/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Hyperf\Task\TaskExecutor;
use Hyperf\Utils\Context;
use Hyperf\View\Engine\EngineInterface;
use Hyperf\View\Engine\SmartyEngine;
use Hyperf\View\Engine\NoneEngine;
use Hyperf\View\Exception\EngineNotFindException;
use Hyperf\View\Exception\RenderException;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -47,7 +47,7 @@ class Render implements RenderInterface

public function __construct(ContainerInterface $container, ConfigInterface $config)
{
$engine = $config->get('view.engine', SmartyEngine::class);
$engine = $config->get('view.engine', NoneEngine::class);
if (! $container->has($engine)) {
throw new EngineNotFindException("{$engine} engine is not found.");
}
Expand Down
29 changes: 29 additions & 0 deletions tests/NoneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\View;

use Hyperf\View\Engine\NoneEngine;
use PHPUnit\Framework\TestCase;

/**
* @internal
* @coversNothing
*/
class NoneTest extends TestCase
{
public function testRender()
{
$content = (new NoneEngine())->render('/', [], []);

$this->assertNotEmpty($content);
}
}

0 comments on commit 844dbf8

Please sign in to comment.