|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Controller |
|
17 * @subpackage Zend_Controller_Action |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @version $Id: Layout.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 */ |
|
22 |
|
23 /** Zend_Controller_Action_Helper_Abstract */ |
|
24 require_once 'Zend/Controller/Action/Helper/Abstract.php'; |
|
25 |
|
26 /** |
|
27 * Helper for interacting with Zend_Layout objects |
|
28 * |
|
29 * @uses Zend_Controller_Action_Helper_Abstract |
|
30 * @category Zend |
|
31 * @package Zend_Controller |
|
32 * @subpackage Zend_Controller_Action |
|
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
35 */ |
|
36 class Zend_Layout_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract |
|
37 { |
|
38 /** |
|
39 * @var Zend_Controller_Front |
|
40 */ |
|
41 protected $_frontController; |
|
42 |
|
43 /** |
|
44 * @var Zend_Layout |
|
45 */ |
|
46 protected $_layout; |
|
47 |
|
48 /** |
|
49 * @var bool |
|
50 */ |
|
51 protected $_isActionControllerSuccessful = false; |
|
52 |
|
53 /** |
|
54 * Constructor |
|
55 * |
|
56 * @param Zend_Layout $layout |
|
57 * @return void |
|
58 */ |
|
59 public function __construct(Zend_Layout $layout = null) |
|
60 { |
|
61 if (null !== $layout) { |
|
62 $this->setLayoutInstance($layout); |
|
63 } else { |
|
64 /** |
|
65 * @see Zend_Layout |
|
66 */ |
|
67 require_once 'Zend/Layout.php'; |
|
68 $layout = Zend_Layout::getMvcInstance(); |
|
69 } |
|
70 |
|
71 if (null !== $layout) { |
|
72 $pluginClass = $layout->getPluginClass(); |
|
73 $front = $this->getFrontController(); |
|
74 if ($front->hasPlugin($pluginClass)) { |
|
75 $plugin = $front->getPlugin($pluginClass); |
|
76 $plugin->setLayoutActionHelper($this); |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 public function init() |
|
82 { |
|
83 $this->_isActionControllerSuccessful = false; |
|
84 } |
|
85 |
|
86 /** |
|
87 * Get front controller instance |
|
88 * |
|
89 * @return Zend_Controller_Front |
|
90 */ |
|
91 public function getFrontController() |
|
92 { |
|
93 if (null === $this->_frontController) { |
|
94 /** |
|
95 * @see Zend_Controller_Front |
|
96 */ |
|
97 require_once 'Zend/Controller/Front.php'; |
|
98 $this->_frontController = Zend_Controller_Front::getInstance(); |
|
99 } |
|
100 |
|
101 return $this->_frontController; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Get layout object |
|
106 * |
|
107 * @return Zend_Layout |
|
108 */ |
|
109 public function getLayoutInstance() |
|
110 { |
|
111 if (null === $this->_layout) { |
|
112 /** |
|
113 * @see Zend_Layout |
|
114 */ |
|
115 require_once 'Zend/Layout.php'; |
|
116 if (null === ($this->_layout = Zend_Layout::getMvcInstance())) { |
|
117 $this->_layout = new Zend_Layout(); |
|
118 } |
|
119 } |
|
120 |
|
121 return $this->_layout; |
|
122 } |
|
123 |
|
124 /** |
|
125 * Set layout object |
|
126 * |
|
127 * @param Zend_Layout $layout |
|
128 * @return Zend_Layout_Controller_Action_Helper_Layout |
|
129 */ |
|
130 public function setLayoutInstance(Zend_Layout $layout) |
|
131 { |
|
132 $this->_layout = $layout; |
|
133 return $this; |
|
134 } |
|
135 |
|
136 /** |
|
137 * Mark Action Controller (according to this plugin) as Running successfully |
|
138 * |
|
139 * @return Zend_Layout_Controller_Action_Helper_Layout |
|
140 */ |
|
141 public function postDispatch() |
|
142 { |
|
143 $this->_isActionControllerSuccessful = true; |
|
144 return $this; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Did the previous action successfully complete? |
|
149 * |
|
150 * @return bool |
|
151 */ |
|
152 public function isActionControllerSuccessful() |
|
153 { |
|
154 return $this->_isActionControllerSuccessful; |
|
155 } |
|
156 |
|
157 /** |
|
158 * Strategy pattern; call object as method |
|
159 * |
|
160 * Returns layout object |
|
161 * |
|
162 * @return Zend_Layout |
|
163 */ |
|
164 public function direct() |
|
165 { |
|
166 return $this->getLayoutInstance(); |
|
167 } |
|
168 |
|
169 /** |
|
170 * Proxy method calls to layout object |
|
171 * |
|
172 * @param string $method |
|
173 * @param array $args |
|
174 * @return mixed |
|
175 */ |
|
176 public function __call($method, $args) |
|
177 { |
|
178 $layout = $this->getLayoutInstance(); |
|
179 if (method_exists($layout, $method)) { |
|
180 return call_user_func_array(array($layout, $method), $args); |
|
181 } |
|
182 |
|
183 require_once 'Zend/Layout/Exception.php'; |
|
184 throw new Zend_Layout_Exception(sprintf("Invalid method '%s' called on layout action helper", $method)); |
|
185 } |
|
186 } |