PageRenderTime 1370ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/View/Helper/Partial.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 149 lines | 65 code | 10 blank | 74 comment | 16 complexity | b489093be28d203c7f6a78dd8bba4b0d 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_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id: Partial.php 23775 2011-03-01 17:25:24Z ralph $
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_View_Helper_Abstract.php */
  23. require_once 'Zend/View/Helper/Abstract.php';
  24. /**
  25. * Helper for rendering a template fragment in its own variable scope.
  26. *
  27. * @package Zend_View
  28. * @subpackage Helper
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_View_Helper_Partial extends Zend_View_Helper_Abstract
  33. {
  34. /**
  35. * Variable to which object will be assigned
  36. * @var string
  37. */
  38. protected $_objectKey;
  39. /**
  40. * Renders a template fragment within a variable scope distinct from the
  41. * calling View object.
  42. *
  43. * If no arguments are passed, returns the helper instance.
  44. *
  45. * If the $model is an array, it is passed to the view object's assign()
  46. * method.
  47. *
  48. * If the $model is an object, it first checks to see if the object
  49. * implements a 'toArray' method; if so, it passes the result of that
  50. * method to to the view object's assign() method. Otherwise, the result of
  51. * get_object_vars() is passed.
  52. *
  53. * @param string $name Name of view script
  54. * @param string|array $module If $model is empty, and $module is an array,
  55. * these are the variables to populate in the
  56. * view. Otherwise, the module in which the
  57. * partial resides
  58. * @param array $model Variables to populate in the view
  59. * @return string|Zend_View_Helper_Partial
  60. */
  61. public function partial($name = null, $module = null, $model = null)
  62. {
  63. if (0 == func_num_args()) {
  64. return $this;
  65. }
  66. $view = $this->cloneView();
  67. if (isset($this->partialCounter)) {
  68. $view->partialCounter = $this->partialCounter;
  69. }
  70. if ((null !== $module) && is_string($module)) {
  71. require_once 'Zend/Controller/Front.php';
  72. $moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module);
  73. if (null === $moduleDir) {
  74. require_once 'Zend/View/Helper/Partial/Exception.php';
  75. $e = new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist');
  76. $e->setView($this->view);
  77. throw $e;
  78. }
  79. $viewsDir = dirname($moduleDir) . '/views';
  80. $view->addBasePath($viewsDir);
  81. } elseif ((null == $model) && (null !== $module)
  82. && (is_array($module) || is_object($module)))
  83. {
  84. $model = $module;
  85. }
  86. if (!empty($model)) {
  87. if (is_array($model)) {
  88. $view->assign($model);
  89. } elseif (is_object($model)) {
  90. if (null !== ($objectKey = $this->getObjectKey())) {
  91. $view->assign($objectKey, $model);
  92. } elseif (method_exists($model, 'toArray')) {
  93. $view->assign($model->toArray());
  94. } else {
  95. $view->assign(get_object_vars($model));
  96. }
  97. }
  98. }
  99. return $view->render($name);
  100. }
  101. /**
  102. * Clone the current View
  103. *
  104. * @return Zend_View_Interface
  105. */
  106. public function cloneView()
  107. {
  108. $view = clone $this->view;
  109. $view->clearVars();
  110. return $view;
  111. }
  112. /**
  113. * Set object key
  114. *
  115. * @param string $key
  116. * @return Zend_View_Helper_Partial
  117. */
  118. public function setObjectKey($key)
  119. {
  120. if (null === $key) {
  121. $this->_objectKey = null;
  122. } else {
  123. $this->_objectKey = (string) $key;
  124. }
  125. return $this;
  126. }
  127. /**
  128. * Retrieve object key
  129. *
  130. * The objectKey is the variable to which an object in the iterator will be
  131. * assigned.
  132. *
  133. * @return null|string
  134. */
  135. public function getObjectKey()
  136. {
  137. return $this->_objectKey;
  138. }
  139. }