web/Zend/Dojo/View/Helper/CustomDijit.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: CustomDijit.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /** Zend_Dojo_View_Helper_DijitContainer */
       
    24 require_once 'Zend/Dojo/View/Helper/DijitContainer.php';
       
    25 
       
    26 /**
       
    27  * Arbitrary dijit support
       
    28  *
       
    29  * @uses       Zend_Dojo_View_Helper_DijitContainer
       
    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_CustomDijit extends Zend_Dojo_View_Helper_DijitContainer
       
    36 {
       
    37     /**
       
    38      * Default dojoType; set the value when extending
       
    39      * @var string
       
    40      */
       
    41     protected $_defaultDojoType;
       
    42 
       
    43     /**
       
    44      * Render a custom dijit
       
    45      *
       
    46      * Requires that either the {@link $_defaultDojotype} property is set, or
       
    47      * that you pass a value to the "dojoType" key of the $params argument.
       
    48      *
       
    49      * @param  string $id
       
    50      * @param  string $value
       
    51      * @param  array $params
       
    52      * @param  array $attribs
       
    53      * @return string|Zend_Dojo_View_Helper_CustomDijit
       
    54      */
       
    55     public function customDijit($id = null, $value = null, array $params = array(), array $attribs = array())
       
    56     {
       
    57         if (null === $id) {
       
    58             return $this;
       
    59         }
       
    60 
       
    61         if (!array_key_exists('dojoType', $params)
       
    62             && (null === $this->_defaultDojoType)
       
    63         ) {
       
    64             require_once 'Zend/Dojo/View/Exception.php';
       
    65             throw new Zend_Dojo_View_Exception('No dojoType specified; cannot create dijit');
       
    66         } elseif (array_key_exists('dojoType', $params)) {
       
    67             $this->_dijit  = $params['dojoType'];
       
    68             $this->_module = $params['dojoType'];
       
    69             unset($params['dojoType']);
       
    70         } else {
       
    71             $this->_dijit  = $this->_defaultDojoType;
       
    72             $this->_module = $this->_defaultDojoType;
       
    73         }
       
    74 
       
    75         if (array_key_exists('rootNode', $params)) {
       
    76             $this->setRootNode($params['rootNode']);
       
    77             unset($params['rootNode']);
       
    78         }
       
    79 
       
    80         return $this->_createLayoutContainer($id, $value, $params, $attribs);
       
    81     }
       
    82 
       
    83     /**
       
    84      * Begin capturing content.
       
    85      *
       
    86      * Requires that either the {@link $_defaultDojotype} property is set, or
       
    87      * that you pass a value to the "dojoType" key of the $params argument.
       
    88      *
       
    89      * @param  string $id
       
    90      * @param  array $params
       
    91      * @param  array $attribs
       
    92      * @return void
       
    93      */
       
    94     public function captureStart($id, array $params = array(), array $attribs = array())
       
    95     {
       
    96         if (!array_key_exists('dojoType', $params)
       
    97             && (null === $this->_defaultDojoType)
       
    98         ) {
       
    99             require_once 'Zend/Dojo/View/Exception.php';
       
   100             throw new Zend_Dojo_View_Exception('No dojoType specified; cannot create dijit');
       
   101         } elseif (array_key_exists('dojoType', $params)) {
       
   102             $this->_dijit  = $params['dojoType'];
       
   103             $this->_module = $params['dojoType'];
       
   104             unset($params['dojoType']);
       
   105         } else {
       
   106             $this->_dijit  = $this->_defaultDojoType;
       
   107             $this->_module = $this->_defaultDojoType;
       
   108         }
       
   109 
       
   110         return parent::captureStart($id, $params, $attribs);
       
   111     }
       
   112 }