-
Notifications
You must be signed in to change notification settings - Fork 1
/
NativeTplHeir.php
43 lines (37 loc) · 1.07 KB
/
NativeTplHeir.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php declare(strict_types=1);
/**
* @license MIT
*
* @author Ilya Dashevsky
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
class NativeTplHeir {
private static array $renderersMap = []; // map slotName -> list or renderes
public static ?string $currentRender = null;
public static function handleBlock(string $name, Closure $render = null, bool $output = false) {
self::$currentRender = $name;
if (!isset(self::$renderersMap[$name])) {
self::$renderersMap[$name] = [];
}
if ($render) {
array_push(self::$renderersMap[$name], $render);
}
if ($output) {
$render = array_shift(self::$renderersMap[$name]);
if ($render) {
$render();
}
}
}
}
function block(string $name, Closure $render) {
NativeTplHeir::handleBlock($name, $render);
}
function slot(string $name, Closure $render = null) {
NativeTplHeir::handleBlock($name, $render, true);
}
function super() {
NativeTplHeir::handleBlock(NativeTplHeir::$currentRender, null, true);
}