fignon/fignon-view-engine

Fignon View Engine 包是一个简单的抽象类,你可以扩展它,轻松地将任何 PHP 模板引擎集成到 Fignon 中。

0.0.1 2024-02-16 12:39 UTC

This package is auto-updated.

Last update: 2024-09-16 14:22:28 UTC


README

这是一个接口,用于简化将任何 PHP 模板引擎集成到 Fignon 框架中使用的流程。

查看一些具体的实现示例,使用

注意

  • 如果你不需要整合上述未列出的模板,则不需要此包。

  • 如果你只需要使用 Twig 或上述列出的任何一种,只需使用 composer 获取它,并开始使用 Fignon 框架构建。

如果你真的需要它

composer require dahkenangnon/fignon-view-engine

那么,你可以这样使用

namespace App\ViewsEngine; // This namespace is up to you

use Fignon\Extra\ViewEngine; // Use the Fignon View Engine integration interface

/**
 * View Engine, 
 */
class MyViewEngine implements ViewEngine
{

    public function init(string $templatePath = null, string $templateCachedPath = null, array $options = []): ViewEngine {

        // Init you view engine and return $this;
    }


    public function render(string $viewPath = '', $locals = [], array $options = []): ?string
    {

        // Return the rendered string from your view engine
    }
}

然后,你可以像这样使用你的新视图引擎集成

//app.php (or index.php) depending of how you call you entry point
declare(strict_types=1);

include_once __DIR__ . "/../vendor/autoload.php";

use Fignon\Tunnel;
use App\Features\Features;
use App\ViewsEngine\MyViewEngine;

$app = new Tunnel();
$app->set('env', 'development');
// ... other middlewares

// View engine initialization
$app->set('views', dirname(__DIR__) . '/templates');
$app->set('views cache', dirname(__DIR__) . '/var/cache');
$app->set('view engine options', []); // Add options to the view engine
$app->engine('my-view-engine-name', new MyViewEngine()); 

$app->set('case sensitive routing', true);
//  ... other middlewares


(new Features($app))->bootstrap();

$app->listen();