- This topic has 2 replies, 1 voice, and was last updated 2 months, 1 week ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Small conception of a rendering engine uses DTOs and viewfiles
I highly suggest making Renderable a trait rather than requiring one to extend a base class.
Also see readme: https://github.com/olleharstedt/DTORenderer
Unfortunately not pure data-transfer objects, since I needed to be able to extract private object properties. A future immutability feature could solve this.
Viewfile example:
<div>
<?php foreach ($buttons as $button): ?>
<?= render($button); ?>
<?php endforeach; ?>
</div>
View object example:
class ButtonGroup extends BaseRenderable
{
/** @var Button[] */
protected $buttons = [];
/** @var string Optional, defaults to classname */
protected $viewfile = ‘views/buttongroup’;
}
Usage example:
$buttonGroup = new ButtonGroup([‘buttons’ => [$button1, $button2]]);
$renderer = new Renderer();
$renderer->filetype = ‘php’;
echo $renderer->render($buttonGroup);