glaubinix/symfony-template-response 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

glaubinix/symfony-template-response

最新稳定版本:3.1

Composer 安装命令:

composer require glaubinix/symfony-template-response

包简介

symfony template response silex

README 文档

README

Build status: Build Status

Using the TemplateResponse will help you to build Controllers which are not tightly coupled to a certain Framework. In the case of Symfony/Silex this mostly means not injecting the ServiceContainer/Application to your Controllers.

Installation

The easiest way to install this library is to use Composer. Add the package "glaubinix/symfony-template-response" to your composer.json.

{
    "require": {
        "glaubinix/symfony-template-response": "@stable"
    }
}

Usage

To be able to use the TemplateResponse simply register the Listener.

Usage with symfony framework bundle

If you are using the framework bundle simply add this to your service config.

<service id="template_response.view_listener" class="Glaubinix\TemplateResponse\TemplateResponseListener%">
    <argument type="service" id="templating" />

    <tag name="kernel.event_listener" event="kernel.view" method="onKernelResponse" priority="10" />
</service>

Usage with silex and twig

If you are using silex make sure the templating Engine is registered then register the ServiceProvider which is provided with this library.

// In a Provider define the templating engine
$app['templating'] = function(Container $app) {
    return new Symfony\Bridge\Twig\TwigEngine($app['twig'], new \Symfony\Component\Templating\TemplateNameParser());
};

// Register the provider
$app->register(new Glaubinix\TemplateResponse\Silex\TemplateResponseServiceProvider());

// Use the response in 
$app->get('/', function() {
    return new TemplateResponse('template', []);
});

Notes

To make this fully decoupled from Frameworks the TemplateResponse would not have to extend the Symfony Response and instead of simply rendering the content we would have to replace the Response. Once this is done a dedicated ResponseListener for every Framework would allow the usage in all Frameworks.

Maintaing sounds like a huge pain and I dont really see this happening :)

Original idea

First time I saw this idea was in QafooLabsNoFrameworkBundle the implementation is slightly different and depends on the symfony framework bundle which is main the reason I build a simple version for silex.

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-04