germania-kg/twig-requesthandler
Composer 安装命令:
composer require germania-kg/twig-requesthandler
包简介
PSR-15 RequestHandler for rendering Twig templates
README 文档
README
Germania KG · RequestHandler for Twig
Installation
$ composer require germania-kg/twig-requesthandler
Setup
The constructor accepts a Twig Environment and PSR-17 ResponseFactory. This example uses Tobias Nyholm's nyholm/psr7 package: composer require nyholm/psr7
<?php use Germania\TwigRequestHandler\TwigRequestHandler; use Twig\Environment as Twig; use Nyholm\Psr7\Factory\Psr17Factory; // Dependencies $twig = new Twig( ... ); $psr17Factory = new Psr17Factory; // Instantiation $request_handler = new TwigRequestHandler($twig, $psr17Factory);
Usage
Have a ServerRequest at hand and configure it with a template attribute and a context attribute.
- The template attribute must be a string as required by Twig.
- The context attribute must be an array as required by Twig; Instances of ArrayObject will be converted.
N.B. Invalid variable types will lead to a RuntimeException at runtime on request handling, not during configuration!
<?php $request = $psr17Factory->createServerRequest('GET', 'http://tnyholm.se'); $request = $request ->withAttribute('template', 'website.twig') ->withAttribute('context', [ 'title' => 'The Website title', 'company' => 'ACME corp.' ]);
Now, the above RequestHandler can be used as normal:
$response = $request_handler->handle($request); echo $response->getBody()->__toString(); // s.th. like // "<title>The Website title · ACME corp.</title>"
Configuration
You can change these default settings:
$request_handler->setTwig($twig); $request_handler->setResponseFactory($another);
You can change these default settings
$request_handler->setTemplateAttributeName("template") ->setContextAttributeName("context") ->setResponseContentType("text/html") ->setResponseStatusCode(200);
… and the core components:
$request_handler->setTwig($twig) ->setResponseFactory($another);
Issues
Development
Grab and go using one of these:
$ git clone git@github.com:GermaniaKG/TwigRequestHandler.git $ gh repo clone GermaniaKG/TwigRequestHandler
Unit tests
Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit
germania-kg/twig-requesthandler 适用场景与选型建议
germania-kg/twig-requesthandler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「templates」 「psr15」 「requesthandler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 germania-kg/twig-requesthandler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 germania-kg/twig-requesthandler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 germania-kg/twig-requesthandler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
CakePHP 4.x AdminLTE Theme.
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
A Hero for your Laminas and Mezzio application to trap php errors & exceptions
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-20