A simple implementation of Tracy\IBarPanel
that allows you to create custom panels by composition of two templates (for tab and panel respectively) and a data provider which feeds the templates with specific data.
The advantage of using TemplatedBarPanel
instead of implementing the IBarPanel interface directly are:
- Implement just the
TemplateDataProviderInterface
and use your favourite templating engine for tab and panel templates. - You abstract your implementation from a specific templating engine. Once you find a better/faster templating engine you can switch to it by just reimplementing the templates and not the way the data for them are gathered.
- You allow your panels to change their look without having to modify them. You just pass different templates to them.
- PHP 5.6 or PHP 7.0
- slepic/php-template (packagist)
Install with composer
composer require slepic/templated-tracy-bar-panel
When implementing a IBarPanel
for Tracy, instead of implementing the interface directly, create just a factory class, which will instantiate the TemplatedBarPanel
like this:
class Factory
{
/**
* @param ...$dependencies Dependencies specific to your panel.
* @return IBarPanel
*/
public function create(...$dependencies)
{
return new TemplatedBarPanel(
new MyTemplateDataProvider(...$dependencies),
new OutputBufferTemplate(__DIR__ . '/tab.phtml'),
new OutputBufferTemplate(__DIR__ . '/panel.phtml')
);
}
}
You need to implement the TemplateDataProviderInterface
to provide specific data for your templates.
The two templates can be the OutputBufferTemplate
provided by the slepic/php-template package.
But if you prefer a higher level template engine, see slepic/php-template-implementation to see if there is an existing binding for your favourite templating engine.
- Update dependency slepic/php-template to v0.2.
- Changed return type of
TemplateDataProviderInterface::getTabData()
andTemplateDataProviderInterface::getPanelData()
to array. - Changed travis setup to only run tests in oldest and newest php versions supported by this package (that is 5.6 and 7.3).