PageRenderTime 24ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Zend/Dojo/View/Helper/Dojo.php

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