GrafiteInc/Forms

View on GitHub
src/Parsers/HtmlConvertor.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Grafite\Forms\Parsers;

class HtmlConvertor
{
    private $templates = null;

    public function __construct($templates)
    {
        $this->templates = $templates;
    }

    public function render($blocks)
    {
        $result = [];

        foreach ($blocks as $block) {
            if (array_key_exists($block['type'], $this->templates)) {
                $template = $this->templates[$block['type']];
                $data = $block['data'];
                $result[] = call_user_func_array($template, $data);
            }
        }

        return implode($result);
    }
}