@@ -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 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | |
17 | 17 | class dwoowelcome extends Controller |
18 | 18 | { |
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::Controller(); |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::Controller(); |
|
22 | + } |
|
23 | 23 | |
24 | - public function index() |
|
25 | - { |
|
26 | - $this->load->library('Dwootemplate'); |
|
27 | - $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
28 | - $this->dwootemplate->display('dwoowelcome.tpl'); |
|
29 | - } |
|
24 | + public function index() |
|
25 | + { |
|
26 | + $this->load->library('Dwootemplate'); |
|
27 | + $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
28 | + $this->dwootemplate->display('dwoowelcome.tpl'); |
|
29 | + } |
|
30 | 30 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if (!defined('BASEPATH')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // The name of the directory where templates are located. |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if (!defined('BASEPATH')) { |
18 | - exit('No direct script access allowed'); |
|
18 | + exit('No direct script access allowed'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | require 'dwoo/dwooAutoload.php'; |
@@ -39,154 +39,154 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class Dwootemplate extends Dwoo_Core |
41 | 41 | { |
42 | - protected $dwoo_data = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * Constructor for the DwooTemplate engine. |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - // Call parents constructor |
|
50 | - parent::__construct(); |
|
51 | - |
|
52 | - // Set the config settings |
|
53 | - $this->initialize(); |
|
54 | - |
|
55 | - // Assign some defaults to dwoo |
|
56 | - $CI = get_instance(); |
|
57 | - $this->dwoo_data = new Dwoo_Data(); |
|
58 | - $this->dwoo_data->js_files = array(); |
|
59 | - $this->dwoo_data->css_files = array(); |
|
60 | - $this->dwoo_data->CI = $CI; |
|
61 | - $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
62 | - $this->dwoo_data->uniqid = uniqid(); |
|
63 | - $this->dwoo_data->timestamp = mktime(); |
|
64 | - |
|
65 | - log_message('debug', 'Dwoo Template Class Initialized'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Assign data to dwoo data object. |
|
70 | - * |
|
71 | - * @param string $key |
|
72 | - * @param mixed $value |
|
73 | - */ |
|
74 | - public function assign($key, $value) |
|
75 | - { |
|
76 | - $this->dwoo_data->$key = $value; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Add Javascript files to template. |
|
81 | - * |
|
82 | - * @param string $js |
|
83 | - */ |
|
84 | - public function add_js($js) |
|
85 | - { |
|
86 | - $current = $this->dwoo_data->js_files; |
|
87 | - $current[] = $js; |
|
88 | - $this->dwoo_data->js_files = $current; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Add Css stylesheets to template. |
|
93 | - * |
|
94 | - * @param string $css |
|
95 | - */ |
|
96 | - public function add_css($css) |
|
97 | - { |
|
98 | - $current = $this->dwoo_data->css_files; |
|
99 | - $current[] = $css; |
|
100 | - $this->dwoo_data->css_files = $current; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Display or return the compiled template |
|
105 | - * Since we assign the results to the standard CI output module |
|
106 | - * you can also use the helper from CI in your templates!! |
|
107 | - * |
|
108 | - * @param string $sTemplate |
|
109 | - * @param bool $return |
|
110 | - * |
|
111 | - * @return mixed |
|
112 | - */ |
|
113 | - public function display($sTemplate, $return = false) |
|
114 | - { |
|
115 | - // Start benchmark |
|
116 | - $CI = get_instance(); |
|
117 | - $CI->benchmark->mark('dwoo_parse_start'); |
|
118 | - |
|
119 | - // Check if file exists |
|
120 | - if (!file_exists($this->template_dir.$sTemplate)) { |
|
121 | - $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
122 | - show_error($message); |
|
123 | - log_message('error', $message); |
|
124 | - } |
|
125 | - |
|
126 | - // Create new template |
|
127 | - $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
128 | - |
|
129 | - // render the template |
|
130 | - $template = $this->get($tpl, $this->dwoo_data); |
|
131 | - |
|
132 | - // Finish benchmark |
|
133 | - $CI->benchmark->mark('dwoo_parse_end'); |
|
134 | - |
|
135 | - // Return results or not ? |
|
136 | - if ($return == false) { |
|
137 | - $CI->output->final_output = $template; |
|
138 | - } else { |
|
139 | - return $template; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Toggle Codeigniter profiler on/off. |
|
145 | - */ |
|
146 | - public function enable_profiler($toggle = true) |
|
147 | - { |
|
148 | - $CI = get_instance(); |
|
149 | - $CI->output->enable_profiler($toggle); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Set http header. |
|
154 | - * |
|
155 | - * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
156 | - * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
157 | - * |
|
158 | - * @param string $header |
|
159 | - */ |
|
160 | - public function set_header($header) |
|
161 | - { |
|
162 | - $CI = get_instance(); |
|
163 | - $CI->output->set_header($header); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Set status header. |
|
168 | - * |
|
169 | - * @example $this->output->set_status_header('401'); |
|
170 | - * @example // Sets the header as: Unauthorized |
|
171 | - * |
|
172 | - * @param string $header |
|
173 | - */ |
|
174 | - public function set_status_header($header) |
|
175 | - { |
|
176 | - $CI = get_instance(); |
|
177 | - $CI->output->set_status_header($header); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Assign the dwootemplate config items to the instance. |
|
182 | - */ |
|
183 | - private function initialize() |
|
184 | - { |
|
185 | - $CI = get_instance(); |
|
186 | - $CI->config->load('dwootemplate', true); |
|
187 | - $config = $CI->config->item('dwootemplate'); |
|
188 | - foreach ($config as $key => $val) { |
|
189 | - $this->$key = $val; |
|
190 | - } |
|
191 | - } |
|
42 | + protected $dwoo_data = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * Constructor for the DwooTemplate engine. |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + // Call parents constructor |
|
50 | + parent::__construct(); |
|
51 | + |
|
52 | + // Set the config settings |
|
53 | + $this->initialize(); |
|
54 | + |
|
55 | + // Assign some defaults to dwoo |
|
56 | + $CI = get_instance(); |
|
57 | + $this->dwoo_data = new Dwoo_Data(); |
|
58 | + $this->dwoo_data->js_files = array(); |
|
59 | + $this->dwoo_data->css_files = array(); |
|
60 | + $this->dwoo_data->CI = $CI; |
|
61 | + $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
62 | + $this->dwoo_data->uniqid = uniqid(); |
|
63 | + $this->dwoo_data->timestamp = mktime(); |
|
64 | + |
|
65 | + log_message('debug', 'Dwoo Template Class Initialized'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Assign data to dwoo data object. |
|
70 | + * |
|
71 | + * @param string $key |
|
72 | + * @param mixed $value |
|
73 | + */ |
|
74 | + public function assign($key, $value) |
|
75 | + { |
|
76 | + $this->dwoo_data->$key = $value; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Add Javascript files to template. |
|
81 | + * |
|
82 | + * @param string $js |
|
83 | + */ |
|
84 | + public function add_js($js) |
|
85 | + { |
|
86 | + $current = $this->dwoo_data->js_files; |
|
87 | + $current[] = $js; |
|
88 | + $this->dwoo_data->js_files = $current; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Add Css stylesheets to template. |
|
93 | + * |
|
94 | + * @param string $css |
|
95 | + */ |
|
96 | + public function add_css($css) |
|
97 | + { |
|
98 | + $current = $this->dwoo_data->css_files; |
|
99 | + $current[] = $css; |
|
100 | + $this->dwoo_data->css_files = $current; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Display or return the compiled template |
|
105 | + * Since we assign the results to the standard CI output module |
|
106 | + * you can also use the helper from CI in your templates!! |
|
107 | + * |
|
108 | + * @param string $sTemplate |
|
109 | + * @param bool $return |
|
110 | + * |
|
111 | + * @return mixed |
|
112 | + */ |
|
113 | + public function display($sTemplate, $return = false) |
|
114 | + { |
|
115 | + // Start benchmark |
|
116 | + $CI = get_instance(); |
|
117 | + $CI->benchmark->mark('dwoo_parse_start'); |
|
118 | + |
|
119 | + // Check if file exists |
|
120 | + if (!file_exists($this->template_dir.$sTemplate)) { |
|
121 | + $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
122 | + show_error($message); |
|
123 | + log_message('error', $message); |
|
124 | + } |
|
125 | + |
|
126 | + // Create new template |
|
127 | + $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
128 | + |
|
129 | + // render the template |
|
130 | + $template = $this->get($tpl, $this->dwoo_data); |
|
131 | + |
|
132 | + // Finish benchmark |
|
133 | + $CI->benchmark->mark('dwoo_parse_end'); |
|
134 | + |
|
135 | + // Return results or not ? |
|
136 | + if ($return == false) { |
|
137 | + $CI->output->final_output = $template; |
|
138 | + } else { |
|
139 | + return $template; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Toggle Codeigniter profiler on/off. |
|
145 | + */ |
|
146 | + public function enable_profiler($toggle = true) |
|
147 | + { |
|
148 | + $CI = get_instance(); |
|
149 | + $CI->output->enable_profiler($toggle); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Set http header. |
|
154 | + * |
|
155 | + * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
156 | + * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
157 | + * |
|
158 | + * @param string $header |
|
159 | + */ |
|
160 | + public function set_header($header) |
|
161 | + { |
|
162 | + $CI = get_instance(); |
|
163 | + $CI->output->set_header($header); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Set status header. |
|
168 | + * |
|
169 | + * @example $this->output->set_status_header('401'); |
|
170 | + * @example // Sets the header as: Unauthorized |
|
171 | + * |
|
172 | + * @param string $header |
|
173 | + */ |
|
174 | + public function set_status_header($header) |
|
175 | + { |
|
176 | + $CI = get_instance(); |
|
177 | + $CI->output->set_status_header($header); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Assign the dwootemplate config items to the instance. |
|
182 | + */ |
|
183 | + private function initialize() |
|
184 | + { |
|
185 | + $CI = get_instance(); |
|
186 | + $CI->config->load('dwootemplate', true); |
|
187 | + $config = $CI->config->item('dwootemplate'); |
|
188 | + foreach ($config as $key => $val) { |
|
189 | + $this->$key = $val; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | } |
@@ -16,507 +16,507 @@ |
||
16 | 16 | */ |
17 | 17 | class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Core |
|
21 | - */ |
|
22 | - protected $_engine = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Dwoo_Data |
|
26 | - */ |
|
27 | - protected $_dataProvider = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var Dwoo_Compiler |
|
31 | - */ |
|
32 | - protected $_compiler = null; |
|
33 | - |
|
34 | - /** |
|
35 | - * Changing Filter's scope to play nicely. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_filter = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $_templateFileClass = 'Dwoo_Template_File'; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $_templateFileSettings = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var Dwoo_IPluginProxy |
|
53 | - */ |
|
54 | - protected $_pluginProxy = null; |
|
55 | - |
|
56 | - /** |
|
57 | - * Constructor method. |
|
58 | - * See setOptions for $opt details. |
|
59 | - * |
|
60 | - * @see setOptions |
|
61 | - * |
|
62 | - * @param array|Zend_Config List of options or Zend_Config instance |
|
63 | - */ |
|
64 | - public function __construct($opt = array()) |
|
65 | - { |
|
66 | - if (is_array($opt)) { |
|
67 | - $this->setOptions($opt); |
|
68 | - } elseif ($opt instanceof Zend_Config) { |
|
69 | - $this->setConfig($opt); |
|
70 | - } |
|
71 | - |
|
72 | - $this->init(); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Set object state from options array |
|
77 | - * - engine = engine class name|engine object|array of options for engine |
|
78 | - * - dataProvider = data provider class name|data provider object|array of options for data provider |
|
79 | - * - compiler = compiler class name|compiler object|array of options for compiler |
|
80 | - * - templateFile =. |
|
81 | - * |
|
82 | - * Array of options: |
|
83 | - * - type class name or object for engine, dataProvider or compiler |
|
84 | - * - any set* method (compileDir for setCompileDir ...) |
|
85 | - * |
|
86 | - * @param array $options |
|
87 | - * |
|
88 | - * @return Dwoo_Adapters_ZendFramework_View |
|
89 | - */ |
|
90 | - public function setOptions(array $opt = array()) |
|
91 | - { |
|
92 | - // Making sure that everything is loaded. |
|
93 | - $classes = array('engine', 'dataProvider', 'compiler'); |
|
94 | - |
|
95 | - // Setting options to Dwoo objects... |
|
96 | - foreach ($opt as $type => $settings) { |
|
97 | - if (!method_exists($this, 'set'.$type)) { |
|
98 | - throw new Dwoo_Exception("Unknown type $type"); |
|
99 | - } |
|
100 | - |
|
101 | - if (is_string($settings) || is_object($settings)) { |
|
102 | - call_user_func(array($this, 'set'.$type), $settings); |
|
103 | - } elseif (is_array($settings)) { |
|
104 | - // Set requested class |
|
105 | - if (array_key_exists('type', $settings)) { |
|
106 | - call_user_func(array($this, 'set'.$type), $settings['type']); |
|
107 | - } |
|
108 | - |
|
109 | - if (in_array($type, $classes)) { |
|
110 | - // Call get so that the class is initialized |
|
111 | - $rel = call_user_func(array($this, 'get'.$type)); |
|
112 | - |
|
113 | - // Call set*() methods so that all the settings are set. |
|
114 | - foreach ($settings as $method => $value) { |
|
115 | - if (method_exists($rel, 'set'.$method)) { |
|
116 | - call_user_func(array($rel, 'set'.$method), $value); |
|
117 | - } |
|
118 | - } |
|
119 | - } elseif ('templateFile' == $type) { |
|
120 | - // Remember the settings for the templateFile |
|
121 | - $this->_templateFileSettings = $settings; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Set object state from Zend_Config object. |
|
129 | - * |
|
130 | - * @param Zend_Config $config |
|
131 | - * |
|
132 | - * @return Dwoo_Adapters_ZendFramework_View |
|
133 | - */ |
|
134 | - public function setConfig(Zend_Config $config) |
|
135 | - { |
|
136 | - return $this->setOptions($config->toArray()); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Called before template rendering. |
|
141 | - * |
|
142 | - * Binds plugin proxy to the Dwoo. |
|
143 | - * |
|
144 | - * @see Dwoo_Adapters_ZendFramework_View::getPluginProxy(); |
|
145 | - * @see Dwoo_Core::setPluginProxy(); |
|
146 | - */ |
|
147 | - protected function preRender() |
|
148 | - { |
|
149 | - $this->getEngine()->setPluginProxy($this->getPluginProxy()); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Wraper for Dwoo_Data::__set() |
|
154 | - * allows to assign variables using the object syntax. |
|
155 | - * |
|
156 | - * @see Dwoo_Data::__set() |
|
157 | - * |
|
158 | - * @param string $name the variable name |
|
159 | - * @param string $value the value to assign to it |
|
160 | - */ |
|
161 | - public function __set($name, $value) |
|
162 | - { |
|
163 | - $this->getDataProvider()->__set($name, $value); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Sraper for Dwoo_Data::__get() allows to read variables using the object |
|
168 | - * syntax. |
|
169 | - * |
|
170 | - * @see Dwoo_Data::__get() |
|
171 | - * |
|
172 | - * @param string $name the variable name |
|
173 | - * |
|
174 | - * @return mixed |
|
175 | - */ |
|
176 | - public function __get($name) |
|
177 | - { |
|
178 | - return $this->getDataProvider()->__get($name); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Wraper for Dwoo_Data::__isset() |
|
183 | - * supports calls to isset($dwooData->var). |
|
184 | - * |
|
185 | - * @see Dwoo_Data::__isset() |
|
186 | - * |
|
187 | - * @param string $name the variable name |
|
188 | - */ |
|
189 | - public function __isset($name) |
|
190 | - { |
|
191 | - return $this->getDataProvider()->__isset($name); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Wraper for Dwoo_Data::_unset() |
|
196 | - * supports unsetting variables using the object syntax. |
|
197 | - * |
|
198 | - * @see Dwoo_Data::__unset() |
|
199 | - * |
|
200 | - * @param string $name the variable name |
|
201 | - */ |
|
202 | - public function __unset($name) |
|
203 | - { |
|
204 | - $this->getDataProvider()->__unset($name); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Catches clone request and clones data provider. |
|
209 | - */ |
|
210 | - public function __clone() |
|
211 | - { |
|
212 | - $this->setDataProvider(clone $this->getDataProvider()); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Returns plugin proxy interface. |
|
217 | - * |
|
218 | - * @return Dwoo_IPluginProxy |
|
219 | - */ |
|
220 | - public function getPluginProxy() |
|
221 | - { |
|
222 | - if (!$this->_pluginProxy) { |
|
223 | - $this->_pluginProxy = new Dwoo_Adapters_ZendFramework_PluginProxy($this); |
|
224 | - } |
|
225 | - |
|
226 | - return $this->_pluginProxy; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets plugin proxy. |
|
231 | - * |
|
232 | - * @param Dwoo_IPluginProxy |
|
233 | - * |
|
234 | - * @return Dwoo_Adapters_ZendFramework_View |
|
235 | - */ |
|
236 | - public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) |
|
237 | - { |
|
238 | - $this->_pluginProxy = $pluginProxy; |
|
239 | - |
|
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Sets template engine. |
|
245 | - * |
|
246 | - * @param string|Dwoo Object or name of the class |
|
247 | - */ |
|
248 | - public function setEngine($engine) |
|
249 | - { |
|
250 | - // if param given as an object |
|
251 | - if ($engine instanceof Dwoo_Core) { |
|
252 | - $this->_engine = $engine; |
|
253 | - } elseif (is_subclass_of($engine, 'Dwoo') || 'Dwoo' === $engine) { |
|
254 | - $this->_engine = new $engine(); |
|
255 | - } else { |
|
256 | - throw new Dwoo_Exception('Custom engine must be a subclass of Dwoo'); |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Return the Dwoo template engine object. |
|
262 | - * |
|
263 | - * @return Dwoo |
|
264 | - */ |
|
265 | - public function getEngine() |
|
266 | - { |
|
267 | - if (null === $this->_engine) { |
|
268 | - $this->_engine = new Dwoo_Adapters_ZendFramework_Dwoo(); |
|
269 | - } |
|
270 | - |
|
271 | - return $this->_engine; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Sets Dwoo data object. |
|
276 | - * |
|
277 | - * @param string|Dwoo_Data Object or name of the class |
|
278 | - */ |
|
279 | - public function setDataProvider($data) |
|
280 | - { |
|
281 | - if ($data instanceof Dwoo_IDataProvider) { |
|
282 | - $this->_dataProvider = $data; |
|
283 | - } elseif (is_subclass_of($data, 'Dwoo_Data') || 'Dwoo_Data' == $data) { |
|
284 | - $this->_dataProvider = new $data(); |
|
285 | - } else { |
|
286 | - throw new Dwoo_Exception('Custom data provider must be a subclass of Dwoo_Data or instance of Dwoo_IDataProvider'); |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Return the Dwoo data object. |
|
292 | - * |
|
293 | - * @return Dwoo_Data |
|
294 | - */ |
|
295 | - public function getDataProvider() |
|
296 | - { |
|
297 | - if (null === $this->_dataProvider) { |
|
298 | - $this->_dataProvider = new Dwoo_Data(); |
|
299 | - |
|
300 | - // Satisfy Zend_View_Abstract wishes to access this unexisting property |
|
301 | - // by setting it to empty array (see Zend_View_Abstract::_filter) |
|
302 | - $this->_dataProvider->_filter = array(); |
|
303 | - } |
|
304 | - |
|
305 | - return $this->_dataProvider; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Sets Dwoo compiler. |
|
310 | - * |
|
311 | - * @param string|Dwoo_Compiler Object or name of the class |
|
312 | - */ |
|
313 | - public function setCompiler($compiler) |
|
314 | - { |
|
315 | - |
|
316 | - // if param given as an object |
|
317 | - if ($compiler instanceof Dwoo_ICompiler) { |
|
318 | - $this->_compiler = $compiler; |
|
319 | - } |
|
320 | - // if param given as a string |
|
321 | - elseif (is_subclass_of($compiler, 'Dwoo_Compiler') || 'Dwoo_Compiler' == $compiler) { |
|
322 | - $this->_compiler = new $compiler(); |
|
323 | - } else { |
|
324 | - throw new Dwoo_Exception('Custom compiler must be a subclass of Dwoo_Compiler or instance of Dwoo_ICompiler'); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Return the Dwoo compiler object. |
|
330 | - * |
|
331 | - * @return Dwoo_Compiler |
|
332 | - */ |
|
333 | - public function getCompiler() |
|
334 | - { |
|
335 | - if (null === $this->_compiler) { |
|
336 | - $this->_compiler = Dwoo_Compiler::compilerFactory(); |
|
337 | - } |
|
338 | - |
|
339 | - return $this->_compiler; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings. |
|
344 | - * |
|
345 | - * @param string Dwoo_ITemplate $template |
|
346 | - * |
|
347 | - * @return Dwoo_ITemplate |
|
348 | - */ |
|
349 | - public function getTemplateFile($template) |
|
350 | - { |
|
351 | - $templateFileClass = $this->_templateFileClass; |
|
352 | - |
|
353 | - $dwooTemplateFile = new $templateFileClass($template); |
|
354 | - |
|
355 | - if (!($dwooTemplateFile instanceof Dwoo_ITemplate)) { |
|
356 | - throw new Dwoo_Exception('Custom templateFile class must be a subclass of Dwoo_ITemplate'); |
|
357 | - } |
|
358 | - |
|
359 | - foreach ($this->_templateFileSettings as $method => $value) { |
|
360 | - if (method_exists($dwooTemplateFile, 'set'.$method)) { |
|
361 | - call_user_func(array($dwooTemplateFile, 'set'.$method), $value); |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - return $dwooTemplateFile; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Dwoo_ITemplate type of class. |
|
370 | - * |
|
371 | - * @param string Name of the class |
|
372 | - */ |
|
373 | - public function setTemplateFile($tempateFileClass) |
|
374 | - { |
|
375 | - $this->_templateFileClass = $tempateFileClass; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Passes data to Dwoo_Data object. |
|
380 | - * |
|
381 | - * @see Dwoo_Data::assign() |
|
382 | - * |
|
383 | - * @param array|string $name |
|
384 | - * @param mixed $val |
|
385 | - * |
|
386 | - * @return Dwoo_Adapters_ZendFramework_View |
|
387 | - */ |
|
388 | - public function assign($name, $val = null) |
|
389 | - { |
|
390 | - $this->getDataProvider()->assign($name, $val); |
|
391 | - |
|
392 | - return $this; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Return list of all assigned variables. |
|
397 | - * |
|
398 | - * @return array |
|
399 | - */ |
|
400 | - public function getVars() |
|
401 | - { |
|
402 | - return $this->getDataProvider()->getData(); |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Clear all assigned variables. |
|
407 | - * |
|
408 | - * Clears all variables assigned to Zend_View either via {@link assign()} or |
|
409 | - * property overloading ({@link __get()}/{@link __set()}). |
|
410 | - * |
|
411 | - * @return Dwoo_Adapters_ZendFramework_View |
|
412 | - */ |
|
413 | - public function clearVars() |
|
414 | - { |
|
415 | - $this->getDataProvider()->clear(); |
|
416 | - |
|
417 | - return $this; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Wraper for parent's render method so preRender method |
|
422 | - * can be called (that will bind the plugin proxy to the |
|
423 | - * engine. |
|
424 | - * |
|
425 | - * @see Zend_View_Abstract::render |
|
426 | - * |
|
427 | - * @return string The script output |
|
428 | - */ |
|
429 | - public function render($name) |
|
430 | - { |
|
431 | - $this->preRender(); |
|
432 | - |
|
433 | - return parent::render($name); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Processes a view script and outputs it. Output is then |
|
438 | - * passed through filters. |
|
439 | - * |
|
440 | - * @param string $name The script script name to process |
|
441 | - * |
|
442 | - * @return string The script output |
|
443 | - */ |
|
444 | - public function _run() |
|
445 | - { |
|
446 | - echo $this->_engine->get( |
|
447 | - $this->getTemplateFile(func_get_arg(0)), |
|
448 | - $this->getDataProvider(), |
|
449 | - $this->getCompiler() |
|
450 | - ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Add plugin path. |
|
455 | - * |
|
456 | - * @param string $dir Directory |
|
457 | - * |
|
458 | - * @return Dwoo_Adapters_ZendFramework_View |
|
459 | - */ |
|
460 | - public function addPluginDir($dir) |
|
461 | - { |
|
462 | - $this->getEngine()->getLoader()->addDirectory($dir); |
|
463 | - |
|
464 | - return $this; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Set compile path. |
|
469 | - * |
|
470 | - * @param string $dir Directory |
|
471 | - * |
|
472 | - * @return Dwoo_Adapters_ZendFramework_View |
|
473 | - */ |
|
474 | - public function setCompileDir($dir) |
|
475 | - { |
|
476 | - $this->getEngine()->setCompileDir($dir); |
|
477 | - |
|
478 | - return $this; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Set cache path. |
|
483 | - * |
|
484 | - * @param string $dir Directory |
|
485 | - * |
|
486 | - * @return Dwoo_Adapters_ZendFramework_View |
|
487 | - */ |
|
488 | - public function setCacheDir($dir) |
|
489 | - { |
|
490 | - $this->getEngine()->setCacheDir($dir); |
|
491 | - |
|
492 | - return $this; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Set cache lifetime. |
|
497 | - * |
|
498 | - * @param string $seconds Lifetime in seconds |
|
499 | - * |
|
500 | - * @return Dwoo_Adapters_ZendFramework_View |
|
501 | - */ |
|
502 | - public function setCacheLifetime($seconds) |
|
503 | - { |
|
504 | - $this->getEngine()->setCacheTime($seconds); |
|
505 | - |
|
506 | - return $this; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Set charset. |
|
511 | - * |
|
512 | - * @param string $charset |
|
513 | - * |
|
514 | - * @return Dwoo_Adapters_ZendFramework_View |
|
515 | - */ |
|
516 | - public function setCharset($charset) |
|
517 | - { |
|
518 | - $this->_engine->setCharset($charset); |
|
519 | - |
|
520 | - return $this; |
|
521 | - } |
|
19 | + /** |
|
20 | + * @var Core |
|
21 | + */ |
|
22 | + protected $_engine = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Dwoo_Data |
|
26 | + */ |
|
27 | + protected $_dataProvider = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var Dwoo_Compiler |
|
31 | + */ |
|
32 | + protected $_compiler = null; |
|
33 | + |
|
34 | + /** |
|
35 | + * Changing Filter's scope to play nicely. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_filter = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $_templateFileClass = 'Dwoo_Template_File'; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $_templateFileSettings = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var Dwoo_IPluginProxy |
|
53 | + */ |
|
54 | + protected $_pluginProxy = null; |
|
55 | + |
|
56 | + /** |
|
57 | + * Constructor method. |
|
58 | + * See setOptions for $opt details. |
|
59 | + * |
|
60 | + * @see setOptions |
|
61 | + * |
|
62 | + * @param array|Zend_Config List of options or Zend_Config instance |
|
63 | + */ |
|
64 | + public function __construct($opt = array()) |
|
65 | + { |
|
66 | + if (is_array($opt)) { |
|
67 | + $this->setOptions($opt); |
|
68 | + } elseif ($opt instanceof Zend_Config) { |
|
69 | + $this->setConfig($opt); |
|
70 | + } |
|
71 | + |
|
72 | + $this->init(); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Set object state from options array |
|
77 | + * - engine = engine class name|engine object|array of options for engine |
|
78 | + * - dataProvider = data provider class name|data provider object|array of options for data provider |
|
79 | + * - compiler = compiler class name|compiler object|array of options for compiler |
|
80 | + * - templateFile =. |
|
81 | + * |
|
82 | + * Array of options: |
|
83 | + * - type class name or object for engine, dataProvider or compiler |
|
84 | + * - any set* method (compileDir for setCompileDir ...) |
|
85 | + * |
|
86 | + * @param array $options |
|
87 | + * |
|
88 | + * @return Dwoo_Adapters_ZendFramework_View |
|
89 | + */ |
|
90 | + public function setOptions(array $opt = array()) |
|
91 | + { |
|
92 | + // Making sure that everything is loaded. |
|
93 | + $classes = array('engine', 'dataProvider', 'compiler'); |
|
94 | + |
|
95 | + // Setting options to Dwoo objects... |
|
96 | + foreach ($opt as $type => $settings) { |
|
97 | + if (!method_exists($this, 'set'.$type)) { |
|
98 | + throw new Dwoo_Exception("Unknown type $type"); |
|
99 | + } |
|
100 | + |
|
101 | + if (is_string($settings) || is_object($settings)) { |
|
102 | + call_user_func(array($this, 'set'.$type), $settings); |
|
103 | + } elseif (is_array($settings)) { |
|
104 | + // Set requested class |
|
105 | + if (array_key_exists('type', $settings)) { |
|
106 | + call_user_func(array($this, 'set'.$type), $settings['type']); |
|
107 | + } |
|
108 | + |
|
109 | + if (in_array($type, $classes)) { |
|
110 | + // Call get so that the class is initialized |
|
111 | + $rel = call_user_func(array($this, 'get'.$type)); |
|
112 | + |
|
113 | + // Call set*() methods so that all the settings are set. |
|
114 | + foreach ($settings as $method => $value) { |
|
115 | + if (method_exists($rel, 'set'.$method)) { |
|
116 | + call_user_func(array($rel, 'set'.$method), $value); |
|
117 | + } |
|
118 | + } |
|
119 | + } elseif ('templateFile' == $type) { |
|
120 | + // Remember the settings for the templateFile |
|
121 | + $this->_templateFileSettings = $settings; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Set object state from Zend_Config object. |
|
129 | + * |
|
130 | + * @param Zend_Config $config |
|
131 | + * |
|
132 | + * @return Dwoo_Adapters_ZendFramework_View |
|
133 | + */ |
|
134 | + public function setConfig(Zend_Config $config) |
|
135 | + { |
|
136 | + return $this->setOptions($config->toArray()); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Called before template rendering. |
|
141 | + * |
|
142 | + * Binds plugin proxy to the Dwoo. |
|
143 | + * |
|
144 | + * @see Dwoo_Adapters_ZendFramework_View::getPluginProxy(); |
|
145 | + * @see Dwoo_Core::setPluginProxy(); |
|
146 | + */ |
|
147 | + protected function preRender() |
|
148 | + { |
|
149 | + $this->getEngine()->setPluginProxy($this->getPluginProxy()); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Wraper for Dwoo_Data::__set() |
|
154 | + * allows to assign variables using the object syntax. |
|
155 | + * |
|
156 | + * @see Dwoo_Data::__set() |
|
157 | + * |
|
158 | + * @param string $name the variable name |
|
159 | + * @param string $value the value to assign to it |
|
160 | + */ |
|
161 | + public function __set($name, $value) |
|
162 | + { |
|
163 | + $this->getDataProvider()->__set($name, $value); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Sraper for Dwoo_Data::__get() allows to read variables using the object |
|
168 | + * syntax. |
|
169 | + * |
|
170 | + * @see Dwoo_Data::__get() |
|
171 | + * |
|
172 | + * @param string $name the variable name |
|
173 | + * |
|
174 | + * @return mixed |
|
175 | + */ |
|
176 | + public function __get($name) |
|
177 | + { |
|
178 | + return $this->getDataProvider()->__get($name); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Wraper for Dwoo_Data::__isset() |
|
183 | + * supports calls to isset($dwooData->var). |
|
184 | + * |
|
185 | + * @see Dwoo_Data::__isset() |
|
186 | + * |
|
187 | + * @param string $name the variable name |
|
188 | + */ |
|
189 | + public function __isset($name) |
|
190 | + { |
|
191 | + return $this->getDataProvider()->__isset($name); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Wraper for Dwoo_Data::_unset() |
|
196 | + * supports unsetting variables using the object syntax. |
|
197 | + * |
|
198 | + * @see Dwoo_Data::__unset() |
|
199 | + * |
|
200 | + * @param string $name the variable name |
|
201 | + */ |
|
202 | + public function __unset($name) |
|
203 | + { |
|
204 | + $this->getDataProvider()->__unset($name); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Catches clone request and clones data provider. |
|
209 | + */ |
|
210 | + public function __clone() |
|
211 | + { |
|
212 | + $this->setDataProvider(clone $this->getDataProvider()); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Returns plugin proxy interface. |
|
217 | + * |
|
218 | + * @return Dwoo_IPluginProxy |
|
219 | + */ |
|
220 | + public function getPluginProxy() |
|
221 | + { |
|
222 | + if (!$this->_pluginProxy) { |
|
223 | + $this->_pluginProxy = new Dwoo_Adapters_ZendFramework_PluginProxy($this); |
|
224 | + } |
|
225 | + |
|
226 | + return $this->_pluginProxy; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets plugin proxy. |
|
231 | + * |
|
232 | + * @param Dwoo_IPluginProxy |
|
233 | + * |
|
234 | + * @return Dwoo_Adapters_ZendFramework_View |
|
235 | + */ |
|
236 | + public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy) |
|
237 | + { |
|
238 | + $this->_pluginProxy = $pluginProxy; |
|
239 | + |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Sets template engine. |
|
245 | + * |
|
246 | + * @param string|Dwoo Object or name of the class |
|
247 | + */ |
|
248 | + public function setEngine($engine) |
|
249 | + { |
|
250 | + // if param given as an object |
|
251 | + if ($engine instanceof Dwoo_Core) { |
|
252 | + $this->_engine = $engine; |
|
253 | + } elseif (is_subclass_of($engine, 'Dwoo') || 'Dwoo' === $engine) { |
|
254 | + $this->_engine = new $engine(); |
|
255 | + } else { |
|
256 | + throw new Dwoo_Exception('Custom engine must be a subclass of Dwoo'); |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Return the Dwoo template engine object. |
|
262 | + * |
|
263 | + * @return Dwoo |
|
264 | + */ |
|
265 | + public function getEngine() |
|
266 | + { |
|
267 | + if (null === $this->_engine) { |
|
268 | + $this->_engine = new Dwoo_Adapters_ZendFramework_Dwoo(); |
|
269 | + } |
|
270 | + |
|
271 | + return $this->_engine; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Sets Dwoo data object. |
|
276 | + * |
|
277 | + * @param string|Dwoo_Data Object or name of the class |
|
278 | + */ |
|
279 | + public function setDataProvider($data) |
|
280 | + { |
|
281 | + if ($data instanceof Dwoo_IDataProvider) { |
|
282 | + $this->_dataProvider = $data; |
|
283 | + } elseif (is_subclass_of($data, 'Dwoo_Data') || 'Dwoo_Data' == $data) { |
|
284 | + $this->_dataProvider = new $data(); |
|
285 | + } else { |
|
286 | + throw new Dwoo_Exception('Custom data provider must be a subclass of Dwoo_Data or instance of Dwoo_IDataProvider'); |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Return the Dwoo data object. |
|
292 | + * |
|
293 | + * @return Dwoo_Data |
|
294 | + */ |
|
295 | + public function getDataProvider() |
|
296 | + { |
|
297 | + if (null === $this->_dataProvider) { |
|
298 | + $this->_dataProvider = new Dwoo_Data(); |
|
299 | + |
|
300 | + // Satisfy Zend_View_Abstract wishes to access this unexisting property |
|
301 | + // by setting it to empty array (see Zend_View_Abstract::_filter) |
|
302 | + $this->_dataProvider->_filter = array(); |
|
303 | + } |
|
304 | + |
|
305 | + return $this->_dataProvider; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Sets Dwoo compiler. |
|
310 | + * |
|
311 | + * @param string|Dwoo_Compiler Object or name of the class |
|
312 | + */ |
|
313 | + public function setCompiler($compiler) |
|
314 | + { |
|
315 | + |
|
316 | + // if param given as an object |
|
317 | + if ($compiler instanceof Dwoo_ICompiler) { |
|
318 | + $this->_compiler = $compiler; |
|
319 | + } |
|
320 | + // if param given as a string |
|
321 | + elseif (is_subclass_of($compiler, 'Dwoo_Compiler') || 'Dwoo_Compiler' == $compiler) { |
|
322 | + $this->_compiler = new $compiler(); |
|
323 | + } else { |
|
324 | + throw new Dwoo_Exception('Custom compiler must be a subclass of Dwoo_Compiler or instance of Dwoo_ICompiler'); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Return the Dwoo compiler object. |
|
330 | + * |
|
331 | + * @return Dwoo_Compiler |
|
332 | + */ |
|
333 | + public function getCompiler() |
|
334 | + { |
|
335 | + if (null === $this->_compiler) { |
|
336 | + $this->_compiler = Dwoo_Compiler::compilerFactory(); |
|
337 | + } |
|
338 | + |
|
339 | + return $this->_compiler; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings. |
|
344 | + * |
|
345 | + * @param string Dwoo_ITemplate $template |
|
346 | + * |
|
347 | + * @return Dwoo_ITemplate |
|
348 | + */ |
|
349 | + public function getTemplateFile($template) |
|
350 | + { |
|
351 | + $templateFileClass = $this->_templateFileClass; |
|
352 | + |
|
353 | + $dwooTemplateFile = new $templateFileClass($template); |
|
354 | + |
|
355 | + if (!($dwooTemplateFile instanceof Dwoo_ITemplate)) { |
|
356 | + throw new Dwoo_Exception('Custom templateFile class must be a subclass of Dwoo_ITemplate'); |
|
357 | + } |
|
358 | + |
|
359 | + foreach ($this->_templateFileSettings as $method => $value) { |
|
360 | + if (method_exists($dwooTemplateFile, 'set'.$method)) { |
|
361 | + call_user_func(array($dwooTemplateFile, 'set'.$method), $value); |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + return $dwooTemplateFile; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Dwoo_ITemplate type of class. |
|
370 | + * |
|
371 | + * @param string Name of the class |
|
372 | + */ |
|
373 | + public function setTemplateFile($tempateFileClass) |
|
374 | + { |
|
375 | + $this->_templateFileClass = $tempateFileClass; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Passes data to Dwoo_Data object. |
|
380 | + * |
|
381 | + * @see Dwoo_Data::assign() |
|
382 | + * |
|
383 | + * @param array|string $name |
|
384 | + * @param mixed $val |
|
385 | + * |
|
386 | + * @return Dwoo_Adapters_ZendFramework_View |
|
387 | + */ |
|
388 | + public function assign($name, $val = null) |
|
389 | + { |
|
390 | + $this->getDataProvider()->assign($name, $val); |
|
391 | + |
|
392 | + return $this; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Return list of all assigned variables. |
|
397 | + * |
|
398 | + * @return array |
|
399 | + */ |
|
400 | + public function getVars() |
|
401 | + { |
|
402 | + return $this->getDataProvider()->getData(); |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Clear all assigned variables. |
|
407 | + * |
|
408 | + * Clears all variables assigned to Zend_View either via {@link assign()} or |
|
409 | + * property overloading ({@link __get()}/{@link __set()}). |
|
410 | + * |
|
411 | + * @return Dwoo_Adapters_ZendFramework_View |
|
412 | + */ |
|
413 | + public function clearVars() |
|
414 | + { |
|
415 | + $this->getDataProvider()->clear(); |
|
416 | + |
|
417 | + return $this; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Wraper for parent's render method so preRender method |
|
422 | + * can be called (that will bind the plugin proxy to the |
|
423 | + * engine. |
|
424 | + * |
|
425 | + * @see Zend_View_Abstract::render |
|
426 | + * |
|
427 | + * @return string The script output |
|
428 | + */ |
|
429 | + public function render($name) |
|
430 | + { |
|
431 | + $this->preRender(); |
|
432 | + |
|
433 | + return parent::render($name); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Processes a view script and outputs it. Output is then |
|
438 | + * passed through filters. |
|
439 | + * |
|
440 | + * @param string $name The script script name to process |
|
441 | + * |
|
442 | + * @return string The script output |
|
443 | + */ |
|
444 | + public function _run() |
|
445 | + { |
|
446 | + echo $this->_engine->get( |
|
447 | + $this->getTemplateFile(func_get_arg(0)), |
|
448 | + $this->getDataProvider(), |
|
449 | + $this->getCompiler() |
|
450 | + ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Add plugin path. |
|
455 | + * |
|
456 | + * @param string $dir Directory |
|
457 | + * |
|
458 | + * @return Dwoo_Adapters_ZendFramework_View |
|
459 | + */ |
|
460 | + public function addPluginDir($dir) |
|
461 | + { |
|
462 | + $this->getEngine()->getLoader()->addDirectory($dir); |
|
463 | + |
|
464 | + return $this; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Set compile path. |
|
469 | + * |
|
470 | + * @param string $dir Directory |
|
471 | + * |
|
472 | + * @return Dwoo_Adapters_ZendFramework_View |
|
473 | + */ |
|
474 | + public function setCompileDir($dir) |
|
475 | + { |
|
476 | + $this->getEngine()->setCompileDir($dir); |
|
477 | + |
|
478 | + return $this; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Set cache path. |
|
483 | + * |
|
484 | + * @param string $dir Directory |
|
485 | + * |
|
486 | + * @return Dwoo_Adapters_ZendFramework_View |
|
487 | + */ |
|
488 | + public function setCacheDir($dir) |
|
489 | + { |
|
490 | + $this->getEngine()->setCacheDir($dir); |
|
491 | + |
|
492 | + return $this; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Set cache lifetime. |
|
497 | + * |
|
498 | + * @param string $seconds Lifetime in seconds |
|
499 | + * |
|
500 | + * @return Dwoo_Adapters_ZendFramework_View |
|
501 | + */ |
|
502 | + public function setCacheLifetime($seconds) |
|
503 | + { |
|
504 | + $this->getEngine()->setCacheTime($seconds); |
|
505 | + |
|
506 | + return $this; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Set charset. |
|
511 | + * |
|
512 | + * @param string $charset |
|
513 | + * |
|
514 | + * @return Dwoo_Adapters_ZendFramework_View |
|
515 | + */ |
|
516 | + public function setCharset($charset) |
|
517 | + { |
|
518 | + $this->_engine->setCharset($charset); |
|
519 | + |
|
520 | + return $this; |
|
521 | + } |
|
522 | 522 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | */ |
17 | 17 | class Dwoo_Adapters_ZendFramework_Dwoo extends Dwoo_Core |
18 | 18 | { |
19 | - /** |
|
20 | - * Redirects all unknown properties to plugin proxy |
|
21 | - * to support $this->viewVariable from within templates. |
|
22 | - * |
|
23 | - * @param string $name Property name |
|
24 | - * |
|
25 | - * @return mixed |
|
26 | - */ |
|
27 | - public function __get($name) |
|
28 | - { |
|
29 | - if (isset($this->getPluginProxy()->view->$name)) { |
|
30 | - return $this->getPluginProxy()->view->$name; |
|
31 | - } |
|
32 | - $trace = debug_backtrace(); |
|
33 | - trigger_error( |
|
34 | - 'Undefined property via __get(): '.$name. |
|
35 | - ' in '.$trace[0]['file']. |
|
36 | - ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
37 | - ); |
|
19 | + /** |
|
20 | + * Redirects all unknown properties to plugin proxy |
|
21 | + * to support $this->viewVariable from within templates. |
|
22 | + * |
|
23 | + * @param string $name Property name |
|
24 | + * |
|
25 | + * @return mixed |
|
26 | + */ |
|
27 | + public function __get($name) |
|
28 | + { |
|
29 | + if (isset($this->getPluginProxy()->view->$name)) { |
|
30 | + return $this->getPluginProxy()->view->$name; |
|
31 | + } |
|
32 | + $trace = debug_backtrace(); |
|
33 | + trigger_error( |
|
34 | + 'Undefined property via __get(): '.$name. |
|
35 | + ' in '.$trace[0]['file']. |
|
36 | + ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
37 | + ); |
|
38 | 38 | |
39 | - return null; |
|
40 | - } |
|
39 | + return null; |
|
40 | + } |
|
41 | 41 | } |