CustomDijit.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Zend_Dojo_View_Helper_DijitContainer */
  23. require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
  24. /**
  25. * Arbitrary dijit support
  26. *
  27. * @uses Zend_Dojo_View_Helper_DijitContainer
  28. * @package Zend_Dojo
  29. * @subpackage View
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Dojo_View_Helper_CustomDijit extends Zend_Dojo_View_Helper_DijitContainer
  34. {
  35. /**
  36. * Default dojoType; set the value when extending
  37. * @var string
  38. */
  39. protected $_defaultDojoType;
  40. /**
  41. * Render a custom dijit
  42. *
  43. * Requires that either the {@link $_defaultDojotype} property is set, or
  44. * that you pass a value to the "dojoType" key of the $params argument.
  45. *
  46. * @param string $id
  47. * @param string $value
  48. * @param array $params
  49. * @param array $attribs
  50. * @return string|Zend_Dojo_View_Helper_CustomDijit
  51. */
  52. public function customDijit($id = null, $value = null, array $params = array(), array $attribs = array())
  53. {
  54. if (null === $id) {
  55. return $this;
  56. }
  57. if (!array_key_exists('dojoType', $params)
  58. && (null === $this->_defaultDojoType)
  59. ) {
  60. require_once 'Zend/Dojo/View/Exception.php';
  61. throw new Zend_Dojo_View_Exception('No dojoType specified; cannot create dijit');
  62. } elseif (array_key_exists('dojoType', $params)) {
  63. $this->_dijit = $params['dojoType'];
  64. $this->_module = $params['dojoType'];
  65. unset($params['dojoType']);
  66. } else {
  67. $this->_dijit = $this->_defaultDojoType;
  68. $this->_module = $this->_defaultDojoType;
  69. }
  70. if (array_key_exists('rootNode', $params)) {
  71. $this->setRootNode($params['rootNode']);
  72. unset($params['rootNode']);
  73. }
  74. return $this->_createLayoutContainer($id, $value, $params, $attribs);
  75. }
  76. /**
  77. * Begin capturing content.
  78. *
  79. * Requires that either the {@link $_defaultDojotype} property is set, or
  80. * that you pass a value to the "dojoType" key of the $params argument.
  81. *
  82. * @param string $id
  83. * @param array $params
  84. * @param array $attribs
  85. * @return void
  86. */
  87. public function captureStart($id, array $params = array(), array $attribs = array())
  88. {
  89. if (!array_key_exists('dojoType', $params)
  90. && (null === $this->_defaultDojoType)
  91. ) {
  92. require_once 'Zend/Dojo/View/Exception.php';
  93. throw new Zend_Dojo_View_Exception('No dojoType specified; cannot create dijit');
  94. } elseif (array_key_exists('dojoType', $params)) {
  95. $this->_dijit = $params['dojoType'];
  96. $this->_module = $params['dojoType'];
  97. unset($params['dojoType']);
  98. } else {
  99. $this->_dijit = $this->_defaultDojoType;
  100. $this->_module = $this->_defaultDojoType;
  101. }
  102. return parent::captureStart($id, $params, $attribs);
  103. }
  104. }