|
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_Dojo |
|
17 * @subpackage View |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @version $Id: Dojo.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_Registry */ |
|
24 require_once 'Zend/Registry.php'; |
|
25 |
|
26 /** |
|
27 * Zend_Dojo_View_Helper_Dojo: Dojo View Helper |
|
28 * |
|
29 * Allows specifying stylesheets, path to dojo, module paths, and onLoad |
|
30 * events. |
|
31 * |
|
32 * @package Zend_Dojo |
|
33 * @subpackage View |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 class Zend_Dojo_View_Helper_Dojo |
|
38 { |
|
39 /**#@+ |
|
40 * Programmatic dijit creation style constants |
|
41 */ |
|
42 const PROGRAMMATIC_SCRIPT = 1; |
|
43 const PROGRAMMATIC_NOSCRIPT = -1; |
|
44 /**#@-*/ |
|
45 |
|
46 /** |
|
47 * @var Zend_View_Interface |
|
48 */ |
|
49 public $view; |
|
50 |
|
51 /** |
|
52 * @var Zend_Dojo_View_Helper_Dojo_Container |
|
53 */ |
|
54 protected $_container; |
|
55 |
|
56 /** |
|
57 * @var bool Whether or not dijits should be declared programmatically |
|
58 */ |
|
59 protected static $_useProgrammatic = true; |
|
60 |
|
61 /** |
|
62 * Initialize helper |
|
63 * |
|
64 * Retrieve container from registry or create new container and store in |
|
65 * registry. |
|
66 * |
|
67 * @return void |
|
68 */ |
|
69 public function __construct() |
|
70 { |
|
71 $registry = Zend_Registry::getInstance(); |
|
72 if (!isset($registry[__CLASS__])) { |
|
73 require_once 'Zend/Dojo/View/Helper/Dojo/Container.php'; |
|
74 $container = new Zend_Dojo_View_Helper_Dojo_Container(); |
|
75 $registry[__CLASS__] = $container; |
|
76 } |
|
77 $this->_container = $registry[__CLASS__]; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Set view object |
|
82 * |
|
83 * @param Zend_Dojo_View_Interface $view |
|
84 * @return void |
|
85 */ |
|
86 public function setView(Zend_View_Interface $view) |
|
87 { |
|
88 $this->view = $view; |
|
89 $this->_container->setView($view); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Return dojo container |
|
94 * |
|
95 * @return Zend_Dojo_View_Helper_Dojo_Container |
|
96 */ |
|
97 public function dojo() |
|
98 { |
|
99 return $this->_container; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Proxy to container methods |
|
104 * |
|
105 * @param string $method |
|
106 * @param array $args |
|
107 * @return mixed |
|
108 * @throws Zend_Dojo_View_Exception For invalid method calls |
|
109 */ |
|
110 public function __call($method, $args) |
|
111 { |
|
112 if (!method_exists($this->_container, $method)) { |
|
113 require_once 'Zend/Dojo/View/Exception.php'; |
|
114 throw new Zend_Dojo_View_Exception(sprintf('Invalid method "%s" called on dojo view helper', $method)); |
|
115 } |
|
116 |
|
117 return call_user_func_array(array($this->_container, $method), $args); |
|
118 } |
|
119 |
|
120 /** |
|
121 * Set whether or not dijits should be created declaratively |
|
122 * |
|
123 * @return void |
|
124 */ |
|
125 public static function setUseDeclarative() |
|
126 { |
|
127 self::$_useProgrammatic = false; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Set whether or not dijits should be created programmatically |
|
132 * |
|
133 * Optionally, specifiy whether or not dijit helpers should generate the |
|
134 * programmatic dojo. |
|
135 * |
|
136 * @param int $style |
|
137 * @return void |
|
138 */ |
|
139 public static function setUseProgrammatic($style = self::PROGRAMMATIC_SCRIPT) |
|
140 { |
|
141 if (!in_array($style, array(self::PROGRAMMATIC_SCRIPT, self::PROGRAMMATIC_NOSCRIPT))) { |
|
142 $style = self::PROGRAMMATIC_SCRIPT; |
|
143 } |
|
144 self::$_useProgrammatic = $style; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Should dijits be created declaratively? |
|
149 * |
|
150 * @return bool |
|
151 */ |
|
152 public static function useDeclarative() |
|
153 { |
|
154 return (false === self::$_useProgrammatic); |
|
155 } |
|
156 |
|
157 /** |
|
158 * Should dijits be created programmatically? |
|
159 * |
|
160 * @return bool |
|
161 */ |
|
162 public static function useProgrammatic() |
|
163 { |
|
164 return (false !== self::$_useProgrammatic); |
|
165 } |
|
166 |
|
167 /** |
|
168 * Should dijits be created programmatically but without scripts? |
|
169 * |
|
170 * @return bool |
|
171 */ |
|
172 public static function useProgrammaticNoScript() |
|
173 { |
|
174 return (self::PROGRAMMATIC_NOSCRIPT === self::$_useProgrammatic); |
|
175 } |
|
176 } |