@@ -26,35 +26,35 @@ |
||
26 | 26 | */ |
27 | 27 | class Exception extends DwooException |
28 | 28 | { |
29 | - protected $compiler; |
|
30 | - protected $template; |
|
29 | + protected $compiler; |
|
30 | + protected $template; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Exception constructor. |
|
34 | - * |
|
35 | - * @param DwooCompiler $compiler |
|
36 | - * @param int $message |
|
37 | - */ |
|
38 | - public function __construct(DwooCompiler $compiler, $message) |
|
39 | - { |
|
40 | - $this->compiler = $compiler; |
|
41 | - $this->template = $compiler->getDwoo()->getTemplate(); |
|
42 | - parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message); |
|
43 | - } |
|
32 | + /** |
|
33 | + * Exception constructor. |
|
34 | + * |
|
35 | + * @param DwooCompiler $compiler |
|
36 | + * @param int $message |
|
37 | + */ |
|
38 | + public function __construct(DwooCompiler $compiler, $message) |
|
39 | + { |
|
40 | + $this->compiler = $compiler; |
|
41 | + $this->template = $compiler->getDwoo()->getTemplate(); |
|
42 | + parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return DwooCompiler |
|
47 | - */ |
|
48 | - public function getCompiler() |
|
49 | - { |
|
50 | - return $this->compiler; |
|
51 | - } |
|
45 | + /** |
|
46 | + * @return DwooCompiler |
|
47 | + */ |
|
48 | + public function getCompiler() |
|
49 | + { |
|
50 | + return $this->compiler; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return \Dwoo\ITemplate|null |
|
55 | - */ |
|
56 | - public function getTemplate() |
|
57 | - { |
|
58 | - return $this->template; |
|
59 | - } |
|
53 | + /** |
|
54 | + * @return \Dwoo\ITemplate|null |
|
55 | + */ |
|
56 | + public function getTemplate() |
|
57 | + { |
|
58 | + return $this->template; |
|
59 | + } |
|
60 | 60 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | { |
40 | 40 | $this->compiler = $compiler; |
41 | 41 | $this->template = $compiler->getDwoo()->getTemplate(); |
42 | - parent::__construct('Compilation error at line ' . $compiler->getLine() . ' in "' . $this->template->getResourceName() . ':' . $this->template->getResourceIdentifier() . '" : ' . $message); |
|
42 | + parent::__construct('Compilation error at line '.$compiler->getLine().' in "'.$this->template->getResourceName().':'.$this->template->getResourceIdentifier().'" : '.$message); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -23,52 +23,52 @@ |
||
23 | 23 | */ |
24 | 24 | interface IPluginProxy |
25 | 25 | { |
26 | - /** |
|
27 | - * Returns true or false to say whether the given plugin is handled by this proxy or not. |
|
28 | - * |
|
29 | - * @param string $name the plugin name |
|
30 | - * |
|
31 | - * @return bool true if the plugin is known and usable, otherwise false |
|
32 | - */ |
|
33 | - public function handles($name); |
|
26 | + /** |
|
27 | + * Returns true or false to say whether the given plugin is handled by this proxy or not. |
|
28 | + * |
|
29 | + * @param string $name the plugin name |
|
30 | + * |
|
31 | + * @return bool true if the plugin is known and usable, otherwise false |
|
32 | + */ |
|
33 | + public function handles($name); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns the code (as a string) to call the plugin |
|
37 | - * (this will be executed at runtime inside the Dwoo class). |
|
38 | - * |
|
39 | - * @param string $name the plugin name |
|
40 | - * @param array $params a parameter array, array key "*" is the rest array |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function getCode($name, $params); |
|
35 | + /** |
|
36 | + * Returns the code (as a string) to call the plugin |
|
37 | + * (this will be executed at runtime inside the Dwoo class). |
|
38 | + * |
|
39 | + * @param string $name the plugin name |
|
40 | + * @param array $params a parameter array, array key "*" is the rest array |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function getCode($name, $params); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns a callback to the plugin, this is used with the reflection API to |
|
48 | - * find out about the plugin's parameter names etc. |
|
49 | - * should you need a rest array without the possibility to edit the |
|
50 | - * plugin's code, you can provide a callback to some |
|
51 | - * other function with the correct parameter signature, i.e. : |
|
52 | - * <code> |
|
53 | - * return array($this, "callbackHelper"); |
|
54 | - * // and callbackHelper would be as such: |
|
55 | - * public function callbackHelper(array $rest=array()){} |
|
56 | - * </code> |
|
57 | - * |
|
58 | - * @param string $name the plugin name |
|
59 | - * |
|
60 | - * @return callback |
|
61 | - */ |
|
62 | - public function getCallback($name); |
|
46 | + /** |
|
47 | + * Returns a callback to the plugin, this is used with the reflection API to |
|
48 | + * find out about the plugin's parameter names etc. |
|
49 | + * should you need a rest array without the possibility to edit the |
|
50 | + * plugin's code, you can provide a callback to some |
|
51 | + * other function with the correct parameter signature, i.e. : |
|
52 | + * <code> |
|
53 | + * return array($this, "callbackHelper"); |
|
54 | + * // and callbackHelper would be as such: |
|
55 | + * public function callbackHelper(array $rest=array()){} |
|
56 | + * </code> |
|
57 | + * |
|
58 | + * @param string $name the plugin name |
|
59 | + * |
|
60 | + * @return callback |
|
61 | + */ |
|
62 | + public function getCallback($name); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns some code that will check if the plugin is loaded and if not load it |
|
66 | - * this is optional, if your plugins are autoloaded or whatever, just return an |
|
67 | - * empty string. |
|
68 | - * |
|
69 | - * @param string $name the plugin name |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getLoader($name); |
|
64 | + /** |
|
65 | + * Returns some code that will check if the plugin is loaded and if not load it |
|
66 | + * this is optional, if your plugins are autoloaded or whatever, just return an |
|
67 | + * empty string. |
|
68 | + * |
|
69 | + * @param string $name the plugin name |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getLoader($name); |
|
74 | 74 | } |
@@ -23,30 +23,30 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class Filter |
25 | 25 | { |
26 | - /** |
|
27 | - * The dwoo instance that runs this filter. |
|
28 | - * |
|
29 | - * @var Core |
|
30 | - */ |
|
31 | - protected $dwoo; |
|
26 | + /** |
|
27 | + * The dwoo instance that runs this filter. |
|
28 | + * |
|
29 | + * @var Core |
|
30 | + */ |
|
31 | + protected $dwoo; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
35 | - * the dwoo instance yourself if you need it. |
|
36 | - * |
|
37 | - * @param Core $dwoo the dwoo instance that runs this plugin |
|
38 | - */ |
|
39 | - public function __construct(Core $dwoo) |
|
40 | - { |
|
41 | - $this->dwoo = $dwoo; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor, if you override it, call parent::__construct($dwoo); or assign |
|
35 | + * the dwoo instance yourself if you need it. |
|
36 | + * |
|
37 | + * @param Core $dwoo the dwoo instance that runs this plugin |
|
38 | + */ |
|
39 | + public function __construct(Core $dwoo) |
|
40 | + { |
|
41 | + $this->dwoo = $dwoo; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Processes the input and returns it filtered. |
|
46 | - * |
|
47 | - * @param string $input the template to process |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function process($input); |
|
44 | + /** |
|
45 | + * Processes the input and returns it filtered. |
|
46 | + * |
|
47 | + * @param string $input the template to process |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function process($input); |
|
52 | 52 | } |
@@ -23,15 +23,15 @@ |
||
23 | 23 | */ |
24 | 24 | interface ILoader |
25 | 25 | { |
26 | - /** |
|
27 | - * Loads a plugin file. |
|
28 | - * the second parameter is used to avoid permanent rehashing when using php functions, |
|
29 | - * however this means that if you have add a plugin that overrides a php function you have |
|
30 | - * to delete the classpath.cache file(s) by hand to force a rehash of the plugins |
|
31 | - * |
|
32 | - * @param string $class the plugin name, without the `Plugin` prefix |
|
33 | - * @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it |
|
34 | - * has just been added, defaults to true |
|
35 | - */ |
|
36 | - public function loadPlugin($class, $forceRehash = true); |
|
26 | + /** |
|
27 | + * Loads a plugin file. |
|
28 | + * the second parameter is used to avoid permanent rehashing when using php functions, |
|
29 | + * however this means that if you have add a plugin that overrides a php function you have |
|
30 | + * to delete the classpath.cache file(s) by hand to force a rehash of the plugins |
|
31 | + * |
|
32 | + * @param string $class the plugin name, without the `Plugin` prefix |
|
33 | + * @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it |
|
34 | + * has just been added, defaults to true |
|
35 | + */ |
|
36 | + public function loadPlugin($class, $forceRehash = true); |
|
37 | 37 | } |
@@ -26,6 +26,6 @@ |
||
26 | 26 | */ |
27 | 27 | interface ICompilable |
28 | 28 | { |
29 | - // this replaces the process function |
|
30 | - //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
29 | + // this replaces the process function |
|
30 | + //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
31 | 31 | } |
@@ -42,118 +42,118 @@ |
||
42 | 42 | */ |
43 | 43 | class DwooView extends View |
44 | 44 | { |
45 | - protected $_sv_template_dir; |
|
46 | - protected $_sv_layout_dir; |
|
47 | - protected $_sv_compile_dir; |
|
48 | - protected $_sv_cache_dir; |
|
49 | - protected $_sv_compile_id; |
|
50 | - |
|
51 | - protected $_dwoo; |
|
52 | - |
|
53 | - public $sv_processedTpl; |
|
45 | + protected $_sv_template_dir; |
|
46 | + protected $_sv_layout_dir; |
|
47 | + protected $_sv_compile_dir; |
|
48 | + protected $_sv_cache_dir; |
|
49 | + protected $_sv_compile_id; |
|
50 | + |
|
51 | + protected $_dwoo; |
|
52 | + |
|
53 | + public $sv_processedTpl; |
|
54 | 54 | |
55 | - public function __construct(&$controller) |
|
56 | - { |
|
57 | - parent::__construct($controller); |
|
58 | - |
|
59 | - $this->ext = '.tpl'; |
|
60 | - |
|
61 | - $this->_sv_template_dir = array( |
|
62 | - VIEWS.$this->viewPath.DS.$this->subDir, |
|
63 | - VIEWS.$this->viewPath, |
|
64 | - VIEWS, |
|
65 | - ); |
|
66 | - |
|
67 | - $this->_sv_layout_dir = array( |
|
68 | - LAYOUTS.$this->subDir, |
|
69 | - VIEWS, |
|
70 | - ); |
|
71 | - |
|
72 | - $this->_sv_compile_dir = TMP.'dwoo'.DS.'compile'; |
|
73 | - $this->_sv_cache_dir = TMP.'dwoo'.DS.'cache'; |
|
74 | - |
|
75 | - $this->_dwoo = new Dwoo_Core($this->_sv_compile_dir, $this->_sv_cache_dir); |
|
76 | - |
|
77 | - $this->_sv_compile_id = $controller->name; |
|
78 | - |
|
79 | - $this->_dwoo->sv_this = $this; |
|
80 | - $this->_dwoo->setSecurityPolicy(); |
|
81 | - |
|
82 | - return; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * changes the template directory. |
|
87 | - */ |
|
88 | - public function setTemplateDir($path = VIEW) |
|
89 | - { |
|
90 | - $old = $this->_sv_template_dir; |
|
91 | - $this->_sv_template_dir = $path; |
|
92 | - |
|
93 | - return $old; |
|
94 | - } |
|
95 | - |
|
96 | - public function getTemplateDir() |
|
97 | - { |
|
98 | - return $this->_sv_template_dir; |
|
99 | - } |
|
100 | - |
|
101 | - public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true) |
|
102 | - { |
|
103 | - // let's determine if this is a layout call or a template call |
|
104 | - // and change the template dir accordingly |
|
105 | - $layout = false; |
|
106 | - if (isset($___data_for_view['content_for_layout'])) { |
|
107 | - $this->_sv_template_dir = $this->_sv_layout_dir; |
|
108 | - $layout = true; |
|
109 | - } |
|
110 | - |
|
111 | - $tpl = new Dwoo_Template_File($___viewFn); |
|
112 | - $data = $___data_for_view; |
|
113 | - |
|
114 | - $data['view'] = $this; |
|
115 | - |
|
116 | - if ($this->helpers != false && $loadHelpers === true) { |
|
117 | - $loadedHelpers = array(); |
|
118 | - $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); |
|
119 | - |
|
120 | - foreach (array_keys($loadedHelpers) as $helper) { |
|
121 | - $camelBackedHelper = strtolower(substr($helper, 0, 1)).substr($helper, 1); |
|
122 | - |
|
123 | - ${$camelBackedHelper} = $loadedHelpers[$helper]; |
|
124 | - |
|
125 | - if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) { |
|
126 | - $subHelpers = ${$camelBackedHelper}->helpers; |
|
127 | - foreach ($subHelpers as $subHelper) { |
|
128 | - ${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper]; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - if (isset($this->passedArgs)) { |
|
133 | - ${$camelBackedHelper}->passedArgs = $this->passedArgs; |
|
134 | - } |
|
135 | - |
|
136 | - $this->loaded[$camelBackedHelper] = ${$camelBackedHelper}; |
|
137 | - |
|
138 | - $data[$camelBackedHelper] = ${$camelBackedHelper}; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - if ($this->helpers != false && $loadHelpers === true) { |
|
143 | - foreach ($loadedHelpers as $helper) { |
|
144 | - if (is_object($helper)) { |
|
145 | - if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) { |
|
146 | - $helper->beforeRender(); |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - return $this->_dwoo->get($tpl, $data); |
|
153 | - } |
|
154 | - |
|
155 | - public function get() |
|
156 | - { |
|
157 | - return $this->_dwoo; |
|
158 | - } |
|
55 | + public function __construct(&$controller) |
|
56 | + { |
|
57 | + parent::__construct($controller); |
|
58 | + |
|
59 | + $this->ext = '.tpl'; |
|
60 | + |
|
61 | + $this->_sv_template_dir = array( |
|
62 | + VIEWS.$this->viewPath.DS.$this->subDir, |
|
63 | + VIEWS.$this->viewPath, |
|
64 | + VIEWS, |
|
65 | + ); |
|
66 | + |
|
67 | + $this->_sv_layout_dir = array( |
|
68 | + LAYOUTS.$this->subDir, |
|
69 | + VIEWS, |
|
70 | + ); |
|
71 | + |
|
72 | + $this->_sv_compile_dir = TMP.'dwoo'.DS.'compile'; |
|
73 | + $this->_sv_cache_dir = TMP.'dwoo'.DS.'cache'; |
|
74 | + |
|
75 | + $this->_dwoo = new Dwoo_Core($this->_sv_compile_dir, $this->_sv_cache_dir); |
|
76 | + |
|
77 | + $this->_sv_compile_id = $controller->name; |
|
78 | + |
|
79 | + $this->_dwoo->sv_this = $this; |
|
80 | + $this->_dwoo->setSecurityPolicy(); |
|
81 | + |
|
82 | + return; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * changes the template directory. |
|
87 | + */ |
|
88 | + public function setTemplateDir($path = VIEW) |
|
89 | + { |
|
90 | + $old = $this->_sv_template_dir; |
|
91 | + $this->_sv_template_dir = $path; |
|
92 | + |
|
93 | + return $old; |
|
94 | + } |
|
95 | + |
|
96 | + public function getTemplateDir() |
|
97 | + { |
|
98 | + return $this->_sv_template_dir; |
|
99 | + } |
|
100 | + |
|
101 | + public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true) |
|
102 | + { |
|
103 | + // let's determine if this is a layout call or a template call |
|
104 | + // and change the template dir accordingly |
|
105 | + $layout = false; |
|
106 | + if (isset($___data_for_view['content_for_layout'])) { |
|
107 | + $this->_sv_template_dir = $this->_sv_layout_dir; |
|
108 | + $layout = true; |
|
109 | + } |
|
110 | + |
|
111 | + $tpl = new Dwoo_Template_File($___viewFn); |
|
112 | + $data = $___data_for_view; |
|
113 | + |
|
114 | + $data['view'] = $this; |
|
115 | + |
|
116 | + if ($this->helpers != false && $loadHelpers === true) { |
|
117 | + $loadedHelpers = array(); |
|
118 | + $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); |
|
119 | + |
|
120 | + foreach (array_keys($loadedHelpers) as $helper) { |
|
121 | + $camelBackedHelper = strtolower(substr($helper, 0, 1)).substr($helper, 1); |
|
122 | + |
|
123 | + ${$camelBackedHelper} = $loadedHelpers[$helper]; |
|
124 | + |
|
125 | + if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) { |
|
126 | + $subHelpers = ${$camelBackedHelper}->helpers; |
|
127 | + foreach ($subHelpers as $subHelper) { |
|
128 | + ${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper]; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + if (isset($this->passedArgs)) { |
|
133 | + ${$camelBackedHelper}->passedArgs = $this->passedArgs; |
|
134 | + } |
|
135 | + |
|
136 | + $this->loaded[$camelBackedHelper] = ${$camelBackedHelper}; |
|
137 | + |
|
138 | + $data[$camelBackedHelper] = ${$camelBackedHelper}; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + if ($this->helpers != false && $loadHelpers === true) { |
|
143 | + foreach ($loadedHelpers as $helper) { |
|
144 | + if (is_object($helper)) { |
|
145 | + if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) { |
|
146 | + $helper->beforeRender(); |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + return $this->_dwoo->get($tpl, $data); |
|
153 | + } |
|
154 | + |
|
155 | + public function get() |
|
156 | + { |
|
157 | + return $this->_dwoo; |
|
158 | + } |
|
159 | 159 | } |
@@ -16,157 +16,157 @@ |
||
16 | 16 | */ |
17 | 17 | class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer |
18 | 18 | { |
19 | - /** |
|
20 | - * @constant string The directory inside the cache dir where templates will |
|
21 | - * be stored in compiled form. |
|
22 | - */ |
|
23 | - const COMPILE_DIR = 'templates'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @constant string The subdirectory inside the compile dir where templates |
|
27 | - * will be stored in compiled form. |
|
28 | - */ |
|
29 | - const COMPILE_SUBDIR = 'dwoo'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @constant string The directory inside the cache dir where cached content |
|
33 | - * will be stored. |
|
34 | - */ |
|
35 | - const CACHE_DIR = 'dwoo'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var Dwoo Dwoo template engine |
|
39 | - */ |
|
40 | - protected $dwoo = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string A string with the default template file extension, |
|
44 | - * including the dot |
|
45 | - */ |
|
46 | - protected $defaultExtension = '.html'; |
|
47 | - |
|
48 | - /** |
|
49 | - * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
50 | - */ |
|
51 | - protected $plugin_dir = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * Pre-serialization callback. |
|
55 | - * |
|
56 | - * Excludes the Dwoo instance to prevent excessive serialization load. |
|
57 | - */ |
|
58 | - public function __sleep() |
|
59 | - { |
|
60 | - $keys = parent::__sleep(); |
|
61 | - unset($keys[array_search('dwoo', $keys)]); |
|
62 | - |
|
63 | - return $keys; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Initialize this Renderer. |
|
68 | - * |
|
69 | - * @param AgaviContext The current application context |
|
70 | - * @param array An associative array of initialization parameters |
|
71 | - */ |
|
72 | - public function initialize(AgaviContext $context, array $parameters = array()) |
|
73 | - { |
|
74 | - parent::initialize($context, $parameters); |
|
75 | - |
|
76 | - $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * provides a custom compiler to the dwoo renderer with optional settings |
|
81 | - * you can set in the agavi output_types.xml config file. |
|
82 | - * |
|
83 | - * @return Dwoo_Compiler |
|
84 | - */ |
|
85 | - public function compilerFactory() |
|
86 | - { |
|
87 | - $compiler = Dwoo_Compiler::compilerFactory(); |
|
88 | - $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
89 | - |
|
90 | - return $compiler; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Grab a cleaned up dwoo instance. |
|
95 | - * |
|
96 | - * @return Dwoo A Dwoo instance |
|
97 | - */ |
|
98 | - protected function getEngine() |
|
99 | - { |
|
100 | - if ($this->dwoo) { |
|
101 | - return $this->dwoo; |
|
102 | - } |
|
103 | - |
|
104 | - // this triggers Agavi autoload |
|
105 | - if (!class_exists('Dwoo')) { |
|
106 | - if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
107 | - // file was dropped with the entire dwoo package |
|
108 | - include dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
109 | - } else { |
|
110 | - // assume the dwoo package is in the include path |
|
111 | - include 'dwooAutoload.php'; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
116 | - |
|
117 | - $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
118 | - AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
119 | - |
|
120 | - $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
121 | - AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
122 | - |
|
123 | - $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
124 | - |
|
125 | - if (!empty($this->plugin_dir)) { |
|
126 | - foreach ((array) $this->plugin_dir as $dir) { |
|
127 | - $this->dwoo->getLoader()->addDirectory($dir); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
132 | - |
|
133 | - return $this->dwoo; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render the presentation and return the result. |
|
138 | - * |
|
139 | - * @param AgaviTemplateLayer The template layer to render |
|
140 | - * @param array The template variables |
|
141 | - * @param array The slots |
|
142 | - * @param array Associative array of additional assigns |
|
143 | - * |
|
144 | - * @return string A rendered result |
|
145 | - */ |
|
146 | - public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
147 | - { |
|
148 | - $engine = $this->getEngine(); |
|
149 | - |
|
150 | - $data = array(); |
|
151 | - if ($this->extractVars) { |
|
152 | - $data = $attributes; |
|
153 | - } else { |
|
154 | - $data[$this->varName] = &$attributes; |
|
155 | - } |
|
156 | - |
|
157 | - $data[$this->slotsVarName] = &$slots; |
|
158 | - |
|
159 | - foreach ($this->assigns as $key => $getter) { |
|
160 | - $data[$key] = $this->getContext()->$getter(); |
|
161 | - } |
|
162 | - |
|
163 | - foreach ($moreAssigns as $key => &$value) { |
|
164 | - if (isset($this->moreAssignNames[$key])) { |
|
165 | - $key = $this->moreAssignNames[$key]; |
|
166 | - } |
|
167 | - $data[$key] = &$value; |
|
168 | - } |
|
169 | - |
|
170 | - return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
171 | - } |
|
19 | + /** |
|
20 | + * @constant string The directory inside the cache dir where templates will |
|
21 | + * be stored in compiled form. |
|
22 | + */ |
|
23 | + const COMPILE_DIR = 'templates'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @constant string The subdirectory inside the compile dir where templates |
|
27 | + * will be stored in compiled form. |
|
28 | + */ |
|
29 | + const COMPILE_SUBDIR = 'dwoo'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @constant string The directory inside the cache dir where cached content |
|
33 | + * will be stored. |
|
34 | + */ |
|
35 | + const CACHE_DIR = 'dwoo'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var Dwoo Dwoo template engine |
|
39 | + */ |
|
40 | + protected $dwoo = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string A string with the default template file extension, |
|
44 | + * including the dot |
|
45 | + */ |
|
46 | + protected $defaultExtension = '.html'; |
|
47 | + |
|
48 | + /** |
|
49 | + * stores the (optional) plugin directories to add to the Dwoo_Loader. |
|
50 | + */ |
|
51 | + protected $plugin_dir = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * Pre-serialization callback. |
|
55 | + * |
|
56 | + * Excludes the Dwoo instance to prevent excessive serialization load. |
|
57 | + */ |
|
58 | + public function __sleep() |
|
59 | + { |
|
60 | + $keys = parent::__sleep(); |
|
61 | + unset($keys[array_search('dwoo', $keys)]); |
|
62 | + |
|
63 | + return $keys; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Initialize this Renderer. |
|
68 | + * |
|
69 | + * @param AgaviContext The current application context |
|
70 | + * @param array An associative array of initialization parameters |
|
71 | + */ |
|
72 | + public function initialize(AgaviContext $context, array $parameters = array()) |
|
73 | + { |
|
74 | + parent::initialize($context, $parameters); |
|
75 | + |
|
76 | + $this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * provides a custom compiler to the dwoo renderer with optional settings |
|
81 | + * you can set in the agavi output_types.xml config file. |
|
82 | + * |
|
83 | + * @return Dwoo_Compiler |
|
84 | + */ |
|
85 | + public function compilerFactory() |
|
86 | + { |
|
87 | + $compiler = Dwoo_Compiler::compilerFactory(); |
|
88 | + $compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false)); |
|
89 | + |
|
90 | + return $compiler; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Grab a cleaned up dwoo instance. |
|
95 | + * |
|
96 | + * @return Dwoo A Dwoo instance |
|
97 | + */ |
|
98 | + protected function getEngine() |
|
99 | + { |
|
100 | + if ($this->dwoo) { |
|
101 | + return $this->dwoo; |
|
102 | + } |
|
103 | + |
|
104 | + // this triggers Agavi autoload |
|
105 | + if (!class_exists('Dwoo')) { |
|
106 | + if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) { |
|
107 | + // file was dropped with the entire dwoo package |
|
108 | + include dirname(__FILE__).'/../../../dwooAutoload.php'; |
|
109 | + } else { |
|
110 | + // assume the dwoo package is in the include path |
|
111 | + include 'dwooAutoload.php'; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + $parentMode = fileperms(AgaviConfig::get('core.cache_dir')); |
|
116 | + |
|
117 | + $compileDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::COMPILE_DIR.DIRECTORY_SEPARATOR.self::COMPILE_SUBDIR; |
|
118 | + AgaviToolkit::mkdir($compileDir, $parentMode, true); |
|
119 | + |
|
120 | + $cacheDir = AgaviConfig::get('core.cache_dir').DIRECTORY_SEPARATOR.self::CACHE_DIR; |
|
121 | + AgaviToolkit::mkdir($cacheDir, $parentMode, true); |
|
122 | + |
|
123 | + $this->dwoo = new Dwoo_Core($compileDir, $cacheDir); |
|
124 | + |
|
125 | + if (!empty($this->plugin_dir)) { |
|
126 | + foreach ((array) $this->plugin_dir as $dir) { |
|
127 | + $this->dwoo->getLoader()->addDirectory($dir); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory')); |
|
132 | + |
|
133 | + return $this->dwoo; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render the presentation and return the result. |
|
138 | + * |
|
139 | + * @param AgaviTemplateLayer The template layer to render |
|
140 | + * @param array The template variables |
|
141 | + * @param array The slots |
|
142 | + * @param array Associative array of additional assigns |
|
143 | + * |
|
144 | + * @return string A rendered result |
|
145 | + */ |
|
146 | + public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
|
147 | + { |
|
148 | + $engine = $this->getEngine(); |
|
149 | + |
|
150 | + $data = array(); |
|
151 | + if ($this->extractVars) { |
|
152 | + $data = $attributes; |
|
153 | + } else { |
|
154 | + $data[$this->varName] = &$attributes; |
|
155 | + } |
|
156 | + |
|
157 | + $data[$this->slotsVarName] = &$slots; |
|
158 | + |
|
159 | + foreach ($this->assigns as $key => $getter) { |
|
160 | + $data[$key] = $this->getContext()->$getter(); |
|
161 | + } |
|
162 | + |
|
163 | + foreach ($moreAssigns as $key => &$value) { |
|
164 | + if (isset($this->moreAssignNames[$key])) { |
|
165 | + $key = $this->moreAssignNames[$key]; |
|
166 | + } |
|
167 | + $data[$key] = &$value; |
|
168 | + } |
|
169 | + |
|
170 | + return $engine->get($layer->getResourceStreamIdentifier(), $data); |
|
171 | + } |
|
172 | 172 | } |
@@ -16,5 +16,5 @@ |
||
16 | 16 | */ |
17 | 17 | function Dwoo_Plugin_t_compile(Dwoo_Compiler $compiler, $string) |
18 | 18 | { |
19 | - return '$this->data[\'tm\']->_('.$string.')'; |
|
19 | + return '$this->data[\'tm\']->_('.$string.')'; |
|
20 | 20 | } |
@@ -16,24 +16,24 @@ |
||
16 | 16 | */ |
17 | 17 | function Dwoo_Plugin_url_compile(Dwoo_Compiler $compiler, $route = null, $params = null, $options = null, array $rest = array()) |
18 | 18 | { |
19 | - if ($params == 'null') { |
|
20 | - if (count($rest)) { |
|
21 | - $params = array(); |
|
22 | - foreach ($rest as $k => $v) { |
|
23 | - if (is_numeric($k)) { |
|
24 | - $params[] = $k.'=>'.$v; |
|
25 | - } else { |
|
26 | - $params[] = '"'.$k.'"=>'.$v; |
|
27 | - } |
|
28 | - } |
|
29 | - $params = 'array('.implode(', ', $params).')'; |
|
30 | - } else { |
|
31 | - $params = 'array()'; |
|
32 | - } |
|
33 | - } |
|
34 | - if ($options == 'null') { |
|
35 | - $options = 'array()'; |
|
36 | - } |
|
19 | + if ($params == 'null') { |
|
20 | + if (count($rest)) { |
|
21 | + $params = array(); |
|
22 | + foreach ($rest as $k => $v) { |
|
23 | + if (is_numeric($k)) { |
|
24 | + $params[] = $k.'=>'.$v; |
|
25 | + } else { |
|
26 | + $params[] = '"'.$k.'"=>'.$v; |
|
27 | + } |
|
28 | + } |
|
29 | + $params = 'array('.implode(', ', $params).')'; |
|
30 | + } else { |
|
31 | + $params = 'array()'; |
|
32 | + } |
|
33 | + } |
|
34 | + if ($options == 'null') { |
|
35 | + $options = 'array()'; |
|
36 | + } |
|
37 | 37 | |
38 | - return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
38 | + return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
39 | 39 | } |