shineunited / conductor-twig-addon
为 Conductor 添加支持使用 Twig 模板构建文件的插件。
1.0.0
2022-11-23 20:39 UTC
Requires
- php: >=8.0
- composer-plugin-api: ^2.0
- shineunited/conductor: ^1.0
- symfony/filesystem: ^6.0
- twig/twig: ^3.4
Requires (Dev)
- composer/composer: ^2.4
- phpcompatibility/php-compatibility: ^9.3
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- shineunited/coding-standard: ^1.0
- squizlabs/php_codesniffer: ^3.0
README
描述
为 Conductor 生成器/蓝图框架添加对 Twig 模板的支持。
安装
要添加 conductor-twig-addon,推荐的方法是通过 composer。
$ composer require shineunited/conductor-twig-addon
使用方法
命名空间提供者功能
命名空间提供者功能注册 Twig 模板包含路径。
示例插件
插件必须实现 Capable 并提供命名空间提供者功能。
<?php namespace Example\Project; use Composer\Composer; use Composer\IO\IOInterface; use ShineUnited\Conductor\Addon\Twig\Capability\NamespaceProvider; use ShineUnited\Conductor\Capability\BlueprintProvider; class ComposerPlugin implements PluginInterface, Capable { public function activate(Composer $composer, IOInterface $io): void { // ... } public function deactivate(Composer $composer, IOInterface $io): void { // ... } public function uninstall(Composer $composer, IOInterface $io): void { // ... } public function getCapabilities(): array { return [ NamespaceProvider::class => ExampleNamespaceProvider::class, BlueprintProvider::class => ExampleBlueprintProvider::class ]; } }
示例提供者
提供者必须实现该功能,并返回一个 TwigNamespaceInterface 对象列表。
<?php namespace Example\Project; use ShineUnited\Conductor\Addon\Twig\Capability\NamespaceProvider; use ShineUnited\Conductor\Addon\Twig\Loader\TwigNamespace; class ExampleNamespaceProvider implements NamespaceProvider { public function getNamespaces(): array { return [ new TwigNamespace('path/to/template/dir', 'optional-namespace'), new TwigNamespace('path/to/global/templates') // load in root namespace ]; } }
然后可以使用 TwigBlueprint 在蓝图提供者中使用这些命名空间。
<?php namespace Example\Project; use ShineUnited\Conductor\Capability\BlueprintProvider; use ShineUnited\Conductor\Addon\Twig\Blueprint\TwigBlueprint; class ExampleBlueprintProvider implements BlueprintProvider { public function getBlueprints(): array { return [ new TwigBlueprint('path/to/file.html', '@namespace/template.twig'), new TwigBlueprint('another/file.html', 'global.twig') ]; } }