diff options
Diffstat (limited to 'library/vendor/Zend/Layout/Controller')
-rw-r--r-- | library/vendor/Zend/Layout/Controller/Action/Helper/Layout.php | 181 | ||||
-rw-r--r-- | library/vendor/Zend/Layout/Controller/Plugin/Layout.php | 155 |
2 files changed, 336 insertions, 0 deletions
diff --git a/library/vendor/Zend/Layout/Controller/Action/Helper/Layout.php b/library/vendor/Zend/Layout/Controller/Action/Helper/Layout.php new file mode 100644 index 0000000..cd3f48c --- /dev/null +++ b/library/vendor/Zend/Layout/Controller/Action/Helper/Layout.php @@ -0,0 +1,181 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Zend_Controller_Action + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Action_Helper_Abstract */ + +/** + * Helper for interacting with Zend_Layout objects + * + * @uses Zend_Controller_Action_Helper_Abstract + * @category Zend + * @package Zend_Controller + * @subpackage Zend_Controller_Action + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Layout_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract +{ + /** + * @var Zend_Controller_Front + */ + protected $_frontController; + + /** + * @var Zend_Layout + */ + protected $_layout; + + /** + * @var bool + */ + protected $_isActionControllerSuccessful = false; + + /** + * Constructor + * + * @param Zend_Layout $layout + * @return void + */ + public function __construct(Zend_Layout $layout = null) + { + if (null !== $layout) { + $this->setLayoutInstance($layout); + } else { + /** + * @see Zend_Layout + */ + $layout = Zend_Layout::getMvcInstance(); + } + + if (null !== $layout) { + $pluginClass = $layout->getPluginClass(); + $front = $this->getFrontController(); + if ($front->hasPlugin($pluginClass)) { + $plugin = $front->getPlugin($pluginClass); + $plugin->setLayoutActionHelper($this); + } + } + } + + public function init() + { + $this->_isActionControllerSuccessful = false; + } + + /** + * Get front controller instance + * + * @return Zend_Controller_Front + */ + public function getFrontController() + { + if (null === $this->_frontController) { + /** + * @see Zend_Controller_Front + */ + $this->_frontController = Zend_Controller_Front::getInstance(); + } + + return $this->_frontController; + } + + /** + * Get layout object + * + * @return Zend_Layout + */ + public function getLayoutInstance() + { + if (null === $this->_layout) { + /** + * @see Zend_Layout + */ + if (null === ($this->_layout = Zend_Layout::getMvcInstance())) { + $this->_layout = new Zend_Layout(); + } + } + + return $this->_layout; + } + + /** + * Set layout object + * + * @param Zend_Layout $layout + * @return Zend_Layout_Controller_Action_Helper_Layout + */ + public function setLayoutInstance(Zend_Layout $layout) + { + $this->_layout = $layout; + return $this; + } + + /** + * Mark Action Controller (according to this plugin) as Running successfully + * + * @return Zend_Layout_Controller_Action_Helper_Layout + */ + public function postDispatch() + { + $this->_isActionControllerSuccessful = true; + return $this; + } + + /** + * Did the previous action successfully complete? + * + * @return bool + */ + public function isActionControllerSuccessful() + { + return $this->_isActionControllerSuccessful; + } + + /** + * Strategy pattern; call object as method + * + * Returns layout object + * + * @return Zend_Layout + */ + public function direct() + { + return $this->getLayoutInstance(); + } + + /** + * Proxy method calls to layout object + * + * @param string $method + * @param array $args + * @return mixed + */ + public function __call($method, $args) + { + $layout = $this->getLayoutInstance(); + if (method_exists($layout, $method)) { + return call_user_func_array(array($layout, $method), $args); + } + + throw new Zend_Layout_Exception(sprintf("Invalid method '%s' called on layout action helper", $method)); + } +} diff --git a/library/vendor/Zend/Layout/Controller/Plugin/Layout.php b/library/vendor/Zend/Layout/Controller/Plugin/Layout.php new file mode 100644 index 0000000..d4855e7 --- /dev/null +++ b/library/vendor/Zend/Layout/Controller/Plugin/Layout.php @@ -0,0 +1,155 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Plugins + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Plugin_Abstract */ + +/** + * Render layouts + * + * @uses Zend_Controller_Plugin_Abstract + * @category Zend + * @package Zend_Controller + * @subpackage Plugins + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Layout_Controller_Plugin_Layout extends Zend_Controller_Plugin_Abstract +{ + protected $_layoutActionHelper = null; + + /** + * @var Zend_Layout + */ + protected $_layout; + + /** + * Constructor + * + * @param Zend_Layout $layout + * @return void + */ + public function __construct(Zend_Layout $layout = null) + { + if (null !== $layout) { + $this->setLayout($layout); + } + } + + /** + * Retrieve layout object + * + * @return Zend_Layout + */ + public function getLayout() + { + return $this->_layout; + } + + /** + * Set layout object + * + * @param Zend_Layout $layout + * @return Zend_Layout_Controller_Plugin_Layout + */ + public function setLayout(Zend_Layout $layout) + { + $this->_layout = $layout; + return $this; + } + + /** + * Set layout action helper + * + * @param Zend_Layout_Controller_Action_Helper_Layout $layoutActionHelper + * @return Zend_Layout_Controller_Plugin_Layout + */ + public function setLayoutActionHelper(Zend_Layout_Controller_Action_Helper_Layout $layoutActionHelper) + { + $this->_layoutActionHelper = $layoutActionHelper; + return $this; + } + + /** + * Retrieve layout action helper + * + * @return Zend_Layout_Controller_Action_Helper_Layout + */ + public function getLayoutActionHelper() + { + return $this->_layoutActionHelper; + } + + /** + * postDispatch() plugin hook -- render layout + * + * @param Zend_Controller_Request_Abstract $request + * @return void + */ + public function postDispatch(Zend_Controller_Request_Abstract $request) + { + $layout = $this->getLayout(); + $helper = $this->getLayoutActionHelper(); + + // Return early if forward detected + if (!$request->isDispatched() + || $this->getResponse()->isRedirect() + || ($layout->getMvcSuccessfulActionOnly() + && (!empty($helper) && !$helper->isActionControllerSuccessful()))) + { + return; + } + + // Return early if layout has been disabled + if (!$layout->isEnabled()) { + return; + } + + $response = $this->getResponse(); + $content = $response->getBody(true); + $contentKey = $layout->getContentKey(); + + if (isset($content['default'])) { + $content[$contentKey] = $content['default']; + } + if ('default' != $contentKey) { + unset($content['default']); + } + + $layout->assign($content); + + $fullContent = null; + $obStartLevel = ob_get_level(); + try { + $fullContent = $layout->render(); + $response->setBody($fullContent); + } catch (Exception $e) { + while (ob_get_level() > $obStartLevel) { + $fullContent .= ob_get_clean(); + } + $request->setParam('layoutFullContent', $fullContent); + $request->setParam('layoutContent', $layout->content); + $response->setBody(null); + throw $e; + } + + } +} |