debuss-a / awareness-mezzio-template
A set of interfaces and traits to make your classes AWARE, just like JCVD.
Package info
github.com/debuss/awareness-mezzio-template
pkg:composer/debuss-a/awareness-mezzio-template
Requires
- php: ^8.0
- mezzio/mezzio-template: ^3.0
This package is auto-updated.
Last update: 2026-04-09 20:01:38 UTC
README
debuss-a/awareness-mezzio-template provides a focused "aware" interface and trait for Mezzio template rendering.
It lets your classes declare that they need a Mezzio\Template\TemplateRendererInterface through a standard setter, making setter injection simple and consistent.
What is included?
This package exposes:
Awareness\TemplateRendererAwareInterfaceAwareness\TemplateRendererAwareTrait
The interface defines a setTemplateRenderer() method, and the trait provides a ready-to-use implementation with a $templateRenderer property.
Why use it?
This package is especially useful when your container supports inflectors or automatic setter injection.
Benefits include:
- ✅ A clear contract for classes that need a template renderer
- ✅ Reusable setter injection without duplicating boilerplate
- ✅ Easy integration with containers that can target an interface
- ✅ Simple testing by injecting a mocked or stubbed renderer
Basic usage
use Awareness\TemplateRendererAwareInterface; use Awareness\TemplateRendererAwareTrait; class PageAction implements TemplateRendererAwareInterface { use TemplateRendererAwareTrait; public function renderHomepage(): string { return $this->templateRenderer->render('app::home'); } }
Using with an inflector
With a container such as League Container, you can automatically inject the Mezzio template renderer into any class implementing TemplateRendererAwareInterface.
use Awareness\TemplateRendererAwareInterface; use League\Container\Container; use Mezzio\Template\TemplateRendererInterface; $container = new Container(); $container->add(TemplateRendererInterface::class, AppTemplateRenderer::class); $container->inflector(TemplateRendererAwareInterface::class) ->invokeMethod('setTemplateRenderer', [TemplateRendererInterface::class]);
Installation
composer require debuss-a/awareness-mezzio-template
Requirements
- PHP 8.0 or higher
mezzio/mezzio-template^3.0