Small conception of a rendering engine uses DTOs and viewfiles

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1954
    usernameqwerty004
    Participant

    Small conception of a rendering engine uses DTOs and viewfiles

    #1955
    sproingie
    Guest

    I highly suggest making Renderable a trait rather than requiring one to extend a base class.

    #1956
    usernameqwerty004
    Guest

    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);

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.