Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / View / Helper / Partial.php
blobda745ed1884d54474d1eee38902a3eaee1173e4e
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\View\Helper;
12 use Zend\View\Exception;
13 use Zend\View\Model\ModelInterface;
15 /**
16 * Helper for rendering a template fragment in its own variable scope.
18 class Partial extends AbstractHelper
20 /**
21 * Variable to which object will be assigned
23 * @var string
25 protected $objectKey;
27 /**
28 * Renders a template fragment within a variable scope distinct from the
29 * calling View object. It proxies to view's render function
31 * @param string|ModelInterface $name Name of view script, or a view model
32 * @param array|object $values Variables to populate in the view
33 * @throws Exception\RuntimeException
34 * @return string|Partial
36 public function __invoke($name = null, $values = null)
38 if (0 == func_num_args()) {
39 return $this;
42 // If we were passed only a view model, just render it.
43 if ($name instanceof ModelInterface) {
44 return $this->getView()->render($name);
47 if (is_scalar($values)) {
48 $values = array();
49 } elseif ($values instanceof ModelInterface) {
50 $values = $values->getVariables();
51 } elseif (is_object($values)) {
52 if (null !== ($objectKey = $this->getObjectKey())) {
53 $values = array($objectKey => $values);
54 } elseif (method_exists($values, 'toArray')) {
55 $values = $values->toArray();
56 } else {
57 $values = get_object_vars($values);
61 return $this->getView()->render($name, $values);
64 /**
65 * Set object key
67 * @param string $key
68 * @return Partial
70 public function setObjectKey($key)
72 if (null === $key) {
73 $this->objectKey = null;
74 return $this;
77 $this->objectKey = (string) $key;
79 return $this;
82 /**
83 * Retrieve object key
85 * The objectKey is the variable to which an object in the iterator will be
86 * assigned.
88 * @return null|string
90 public function getObjectKey()
92 return $this->objectKey;