1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: */
7:
8: namespace Latte\Macros;
9:
10: use Latte,
11: Latte\RuntimeException;
12:
13:
14: /**
15: * Runtime helpers for block macros.
16: *
17: * @author David Grudl
18: */
19: class BlockMacrosRuntime extends Latte\Object
20: {
21:
22: /**
23: * Calls block.
24: * @return void
25: */
26: public static function callBlock(\stdClass $context, $name, array $params)
27: {
28: if (empty($context->blocks[$name])) {
29: throw new RuntimeException("Cannot include undefined block '$name'.");
30: }
31: $block = reset($context->blocks[$name]);
32: $block($context, $params);
33: }
34:
35:
36: /**
37: * Calls parent block.
38: * @return void
39: */
40: public static function callBlockParent(\stdClass $context, $name, array $params)
41: {
42: if (empty($context->blocks[$name]) || ($block = next($context->blocks[$name])) === FALSE) {
43: throw new RuntimeException("Cannot include undefined parent block '$name'.");
44: }
45: $block($context, $params);
46: prev($context->blocks[$name]);
47: }
48:
49: }
50: