setono / php-templates-bundle
一个集成了php模板库的Symfony扩展包
v1.0.0
2020-05-15 13:11 UTC
Requires
- php: ^7.2
- setono/php-templates: ^1.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/framework-bundle: ^4.4 || ^5.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.2
- korbeil/phpstan-generic-rules: ^0.2.4
- matthiasnoback/symfony-dependency-injection-test: ^4.1
- nyholm/symfony-bundle-test: ^1.6
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.23
- phpstan/phpstan-strict-rules: ^0.12.2
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-master
- sylius-labs/coding-standard: ^3.1
- symplify/coding-standard: ^7.1
- thecodingmachine/phpstan-safe-rule: ^1.0
This package is auto-updated.
Last update: 2024-09-15 21:48:06 UTC
README
此扩展包将PHP模板库集成到Symfony中。
安装
步骤 1: 下载
$ composer require setono/php-templates-bundle
步骤 2: 启用扩展包
如果你使用Symfony Flex,它将自动启用。否则,你需要将其添加到config/bundles.php
<?php // config/bundles.php return [ // ... Setono\PhpTemplatesBundle\SetonoPhpTemplatesBundle::class => ['all' => true], // ... ];
使用
服务使用
该扩展包注册了服务setono_php_templates.engine.default
,并将接口Setono\PhpTemplates\Engine\EngineInterface
自动绑定到该默认引擎。这意味着你可以通过接口类型提示来注入引擎
<?php use Setono\PhpTemplates\Engine\EngineInterface; final class YourService { /** @var EngineInterface */ private $engine; public function __construct(EngineInterface $engine) { $this->engine = $engine; } public function __invoke(): string { return $this->engine->render('YourNamespace/template', [ 'parameter' => 'value' ]); } }
模板
该扩展包自动添加了模板引擎的路径。对于扩展包,默认为src/Resources/views/php
,对于应用程序,默认为templates/php
。