2017 © Pedro Peláez
 

library symfony-template-response

symfony template response silex

image

glaubinix/symfony-template-response

symfony template response silex

  • Sunday, January 7, 2018
  • by glaubinix
  • Repository
  • 1 Watchers
  • 2 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

symfony-template-response

Build status: Build Status, (*1)

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., (*2)

Installation

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

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

Usage

To be able to use the TemplateResponse simply register the Listener., (*4)

Usage with symfony framework bundle

If you are using the framework bundle simply add this to your service config., (*5)

<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., (*6)

// 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., (*7)

Maintaing sounds like a huge pain and I dont really see this happening :), (*8)

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., (*9)

The Versions

07/01 2018

dev-master

9999999-dev

symfony template response silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock

07/01 2018

3.1

3.1.0.0

symfony template response silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock

24/05 2016

3.0

3.0.0.0

symfony template response silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock

22/12 2015

2.1.0

2.1.0.0

symfony template response silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock

04/02 2015

2.0.0

2.0.0.0

symfony template response silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock

28/12 2014

1.0

1.0.0.0

Silex twig template response

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stephan Vock