1 | <?php |
||
29 | class LightnCandy extends Flags |
||
30 | { |
||
31 | protected static $lastContext; |
||
32 | public static $lastParsed; |
||
33 | |||
34 | /** |
||
35 | * Compile handlebars template into PHP code. |
||
36 | * |
||
37 | * @param string $template handlebars template string |
||
38 | * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE) |
||
39 | * |
||
40 | * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false. |
||
41 | */ |
||
42 | 642 | public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) { |
|
60 | |||
61 | /** |
||
62 | * Handle exists error and return error status. |
||
63 | * |
||
64 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
65 | * |
||
66 | * @throws \Exception |
||
67 | * @return boolean True when error detected |
||
68 | * |
||
69 | * @expect false when input array('error' => array()) |
||
70 | * @expect true when input array('error' => array('some error'), 'flags' => array('errorlog' => 0, 'exception' => 0)) |
||
71 | */ |
||
72 | 643 | protected static function handleError(&$context) { |
|
73 | 643 | static::$lastContext = $context; |
|
74 | |||
75 | 643 | if (count($context['error'])) { |
|
76 | 68 | if ($context['flags']['errorlog']) { |
|
77 | 1 | error_log(implode("\n", $context['error'])); |
|
78 | } |
||
79 | 68 | if ($context['flags']['exception']) { |
|
80 | 8 | throw new \Exception(implode("\n", $context['error'])); |
|
81 | } |
||
82 | 60 | return true; |
|
83 | } |
||
84 | 641 | return false; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get last compiler context. |
||
89 | * |
||
90 | * @return array<string,array|string|integer> Context data |
||
91 | */ |
||
92 | 211 | public static function getContext() { |
|
95 | |||
96 | /** |
||
97 | * Get a working render function by a string of PHP code. This method may requires php setting allow_url_include=1 and allow_url_fopen=1 , or access right to tmp file system. |
||
98 | * |
||
99 | * @param string $php PHP code |
||
100 | * @param string|null $tmpDir Optional, change temp directory for php include file saved by prepare() when cannot include PHP code with data:// format. |
||
101 | * @param boolean $delete Optional, delete temp php file when set to tru. Default is true, set it to false for debug propose |
||
102 | * |
||
103 | * @return Closure|false result of include() |
||
104 | * |
||
105 | * @deprecated |
||
106 | */ |
||
107 | 545 | public static function prepare($php, $tmpDir = null, $delete = true) { |
|
136 | } |
||
137 | |||
138 |