File indexing completed on 2024-12-29 05:27:35
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dojo 0017 * @subpackage View 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @version $Id$ 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 */ 0022 0023 /** Zend_Registry */ 0024 // require_once 'Zend/Registry.php'; 0025 0026 /** 0027 * Zend_Dojo_View_Helper_Dojo: Dojo View Helper 0028 * 0029 * Allows specifying stylesheets, path to dojo, module paths, and onLoad 0030 * events. 0031 * 0032 * @package Zend_Dojo 0033 * @subpackage View 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Dojo_View_Helper_Dojo 0038 { 0039 /**#@+ 0040 * Programmatic dijit creation style constants 0041 */ 0042 const PROGRAMMATIC_SCRIPT = 1; 0043 const PROGRAMMATIC_NOSCRIPT = -1; 0044 /**#@-*/ 0045 0046 /** 0047 * @var Zend_View_Interface 0048 */ 0049 public $view; 0050 0051 /** 0052 * @var Zend_Dojo_View_Helper_Dojo_Container 0053 */ 0054 protected $_container; 0055 0056 /** 0057 * @var bool Whether or not dijits should be declared programmatically 0058 */ 0059 protected static $_useProgrammatic = true; 0060 0061 /** 0062 * Initialize helper 0063 * 0064 * Retrieve container from registry or create new container and store in 0065 * registry. 0066 * 0067 * @return void 0068 */ 0069 public function __construct() 0070 { 0071 $registry = Zend_Registry::getInstance(); 0072 if (!isset($registry[__CLASS__])) { 0073 // require_once 'Zend/Dojo/View/Helper/Dojo/Container.php'; 0074 $container = new Zend_Dojo_View_Helper_Dojo_Container(); 0075 $registry[__CLASS__] = $container; 0076 } 0077 $this->_container = $registry[__CLASS__]; 0078 } 0079 0080 /** 0081 * Set view object 0082 * 0083 * @param Zend_Dojo_View_Interface $view 0084 * @return void 0085 */ 0086 public function setView(Zend_View_Interface $view) 0087 { 0088 $this->view = $view; 0089 $this->_container->setView($view); 0090 } 0091 0092 /** 0093 * Return dojo container 0094 * 0095 * @return Zend_Dojo_View_Helper_Dojo_Container 0096 */ 0097 public function dojo() 0098 { 0099 return $this->_container; 0100 } 0101 0102 /** 0103 * Proxy to container methods 0104 * 0105 * @param string $method 0106 * @param array $args 0107 * @return mixed 0108 * @throws Zend_Dojo_View_Exception For invalid method calls 0109 */ 0110 public function __call($method, $args) 0111 { 0112 if (!method_exists($this->_container, $method)) { 0113 // require_once 'Zend/Dojo/View/Exception.php'; 0114 throw new Zend_Dojo_View_Exception(sprintf('Invalid method "%s" called on dojo view helper', $method)); 0115 } 0116 0117 return call_user_func_array(array($this->_container, $method), $args); 0118 } 0119 0120 /** 0121 * Set whether or not dijits should be created declaratively 0122 * 0123 * @return void 0124 */ 0125 public static function setUseDeclarative() 0126 { 0127 self::$_useProgrammatic = false; 0128 } 0129 0130 /** 0131 * Set whether or not dijits should be created programmatically 0132 * 0133 * Optionally, specifiy whether or not dijit helpers should generate the 0134 * programmatic dojo. 0135 * 0136 * @param int $style 0137 * @return void 0138 */ 0139 public static function setUseProgrammatic($style = self::PROGRAMMATIC_SCRIPT) 0140 { 0141 if (!in_array($style, array(self::PROGRAMMATIC_SCRIPT, self::PROGRAMMATIC_NOSCRIPT))) { 0142 $style = self::PROGRAMMATIC_SCRIPT; 0143 } 0144 self::$_useProgrammatic = $style; 0145 } 0146 0147 /** 0148 * Should dijits be created declaratively? 0149 * 0150 * @return bool 0151 */ 0152 public static function useDeclarative() 0153 { 0154 return (false === self::$_useProgrammatic); 0155 } 0156 0157 /** 0158 * Should dijits be created programmatically? 0159 * 0160 * @return bool 0161 */ 0162 public static function useProgrammatic() 0163 { 0164 return (false !== self::$_useProgrammatic); 0165 } 0166 0167 /** 0168 * Should dijits be created programmatically but without scripts? 0169 * 0170 * @return bool 0171 */ 0172 public static function useProgrammaticNoScript() 0173 { 0174 return (self::PROGRAMMATIC_NOSCRIPT === self::$_useProgrammatic); 0175 } 0176 }