File indexing completed on 2025-03-02 05:29:31

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_Controller
0017  * @subpackage Zend_Controller_Action
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_Controller_Action_Helper_Abstract */
0024 // require_once 'Zend/Controller/Action/Helper/Abstract.php';
0025 
0026 /**
0027  * Helper for interacting with Zend_Layout objects
0028  *
0029  * @uses       Zend_Controller_Action_Helper_Abstract
0030  * @category   Zend
0031  * @package    Zend_Controller
0032  * @subpackage Zend_Controller_Action
0033  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0034  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0035  */
0036 class Zend_Layout_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
0037 {
0038     /**
0039      * @var Zend_Controller_Front
0040      */
0041     protected $_frontController;
0042 
0043     /**
0044      * @var Zend_Layout
0045      */
0046     protected $_layout;
0047 
0048     /**
0049      * @var bool
0050      */
0051     protected $_isActionControllerSuccessful = false;
0052 
0053     /**
0054      * Constructor
0055      *
0056      * @param  Zend_Layout $layout
0057      * @return void
0058      */
0059     public function __construct(Zend_Layout $layout = null)
0060     {
0061         if (null !== $layout) {
0062             $this->setLayoutInstance($layout);
0063         } else {
0064             /**
0065              * @see Zend_Layout
0066              */
0067             // require_once 'Zend/Layout.php';
0068             $layout = Zend_Layout::getMvcInstance();
0069         }
0070 
0071         if (null !== $layout) {
0072             $pluginClass = $layout->getPluginClass();
0073             $front = $this->getFrontController();
0074             if ($front->hasPlugin($pluginClass)) {
0075                 $plugin = $front->getPlugin($pluginClass);
0076                 $plugin->setLayoutActionHelper($this);
0077             }
0078         }
0079     }
0080 
0081     public function init()
0082     {
0083         $this->_isActionControllerSuccessful = false;
0084     }
0085 
0086     /**
0087      * Get front controller instance
0088      *
0089      * @return Zend_Controller_Front
0090      */
0091     public function getFrontController()
0092     {
0093         if (null === $this->_frontController) {
0094             /**
0095              * @see Zend_Controller_Front
0096              */
0097             // require_once 'Zend/Controller/Front.php';
0098             $this->_frontController = Zend_Controller_Front::getInstance();
0099         }
0100 
0101         return $this->_frontController;
0102     }
0103 
0104     /**
0105      * Get layout object
0106      *
0107      * @return Zend_Layout
0108      */
0109     public function getLayoutInstance()
0110     {
0111         if (null === $this->_layout) {
0112             /**
0113              * @see Zend_Layout
0114              */
0115             // require_once 'Zend/Layout.php';
0116             if (null === ($this->_layout = Zend_Layout::getMvcInstance())) {
0117                 $this->_layout = new Zend_Layout();
0118             }
0119         }
0120 
0121         return $this->_layout;
0122     }
0123 
0124     /**
0125      * Set layout object
0126      *
0127      * @param  Zend_Layout $layout
0128      * @return Zend_Layout_Controller_Action_Helper_Layout
0129      */
0130     public function setLayoutInstance(Zend_Layout $layout)
0131     {
0132         $this->_layout = $layout;
0133         return $this;
0134     }
0135 
0136     /**
0137      * Mark Action Controller (according to this plugin) as Running successfully
0138      *
0139      * @return Zend_Layout_Controller_Action_Helper_Layout
0140      */
0141     public function postDispatch()
0142     {
0143         $this->_isActionControllerSuccessful = true;
0144         return $this;
0145     }
0146 
0147     /**
0148      * Did the previous action successfully complete?
0149      *
0150      * @return bool
0151      */
0152     public function isActionControllerSuccessful()
0153     {
0154         return $this->_isActionControllerSuccessful;
0155     }
0156 
0157     /**
0158      * Strategy pattern; call object as method
0159      *
0160      * Returns layout object
0161      *
0162      * @return Zend_Layout
0163      */
0164     public function direct()
0165     {
0166         return $this->getLayoutInstance();
0167     }
0168 
0169     /**
0170      * Proxy method calls to layout object
0171      *
0172      * @param  string $method
0173      * @param  array $args
0174      * @return mixed
0175      */
0176     public function __call($method, $args)
0177     {
0178         $layout = $this->getLayoutInstance();
0179         if (method_exists($layout, $method)) {
0180             return call_user_func_array(array($layout, $method), $args);
0181         }
0182 
0183         // require_once 'Zend/Layout/Exception.php';
0184         throw new Zend_Layout_Exception(sprintf("Invalid method '%s' called on layout action helper", $method));
0185     }
0186 }