| Total Complexity | 5 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class PugTemplateRenderer implements TemplateRenderer |
||
| 14 | { |
||
| 15 | public const DEFAULT_PATH = 'templates/'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var Pug |
||
| 19 | */ |
||
| 20 | private $pug; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $path; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | private $globals; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | private $config; |
||
| 36 | |||
| 37 | 2 | public function __construct(Pug $pug, array $defaultParams, array $globals, array $config) |
|
| 38 | { |
||
| 39 | 2 | $this->pug = $pug; |
|
| 40 | 2 | $this->globals = $globals; |
|
| 41 | 2 | $this->config = $config; |
|
| 42 | 2 | $this->addPath($this->config['template_path']); |
|
| 43 | 2 | $this->setDefaultParams($defaultParams); |
|
| 44 | 2 | } |
|
| 45 | |||
| 46 | 2 | private function setDefaultParams(array $defaultParams): void |
|
| 47 | { |
||
| 48 | 2 | $this->globals = (array) array_replace_recursive($this->globals, $defaultParams); |
|
| 49 | 2 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $name |
||
| 53 | * @param array $params |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | 1 | public function render(string $name, array $params = []) : string |
|
| 57 | { |
||
| 58 | 1 | return $this->pug->render( |
|
| 59 | 1 | sprintf( |
|
| 60 | 1 | '%s.%s', |
|
| 61 | 1 | $this->path . str_replace('::', '/', $name), |
|
| 62 | 1 | $this->config['extension'] |
|
| 63 | ), |
||
| 64 | 1 | array_merge_recursive($this->globals, $params) |
|
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Add a template path to the engine. |
||
| 70 | * |
||
| 71 | * Adds a template path |
||
| 72 | * |
||
| 73 | * @param string $path |
||
| 74 | */ |
||
| 75 | 2 | private function addPath(string $path) : void |
|
| 78 | 2 | } |
|
| 79 | } |
||
| 80 |