summaryrefslogtreecommitdiff
path: root/src/Compile/ObjectMethodBlockCompiler.php
blob: 6c05c4220d7f3815aee90076bed156fe1c668b20 (plain)
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
44
<?php
/**
 * Smarty Internal Plugin Compile Object Block Function
 * Compiles code for registered objects as block function
 *


 * @author     Uwe Tews
 */

namespace Smarty\Compile;

/**
 * Smarty Internal Plugin Compile Object Block Function Class
 *


 */
class ObjectMethodBlockCompiler extends BlockCompiler {

	/**
	 * @inheritDoc
	 */
	protected function getIsCallableCode($tag, $function): string {
		$callbackObject = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]";
		return "(isset({$callbackObject}) && is_callable(array({$callbackObject}, '{$function}')))";
	}

	/**
	 * @inheritDoc
	 */
	protected function getFullCallbackCode($tag, $function): string {
		$callbackObject = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]";
		return "{$callbackObject}->{$function}";
	}

	/**
	 * @inheritDoc
	 */
	protected function blockIsCacheable(\Smarty\Smarty $smarty, $function): bool {
		return true;
	}

}