1<?php
2/**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license   http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10namespace Zend\View\Helper;
11
12use Zend\View\Model\ModelInterface as Model;
13
14/**
15 * Helper for storing and retrieving the root and current view model
16 */
17class ViewModel extends AbstractHelper
18{
19    /**
20     * @var Model
21     */
22    protected $current;
23
24    /**
25     * @var Model
26     */
27    protected $root;
28
29    /**
30     * Set the current view model
31     *
32     * @param  Model $model
33     * @return ViewModel
34     */
35    public function setCurrent(Model $model)
36    {
37        $this->current = $model;
38        return $this;
39    }
40
41    /**
42     * Get the current view model
43     *
44     * @return null|Model
45     */
46    public function getCurrent()
47    {
48        return $this->current;
49    }
50
51    /**
52     * Is a current view model composed?
53     *
54     * @return bool
55     */
56    public function hasCurrent()
57    {
58        return ($this->current instanceof Model);
59    }
60
61    /**
62     * Set the root view model
63     *
64     * @param  Model $model
65     * @return ViewModel
66     */
67    public function setRoot(Model $model)
68    {
69        $this->root = $model;
70        return $this;
71    }
72
73    /**
74     * Get the root view model
75     *
76     * @return null|Model
77     */
78    public function getRoot()
79    {
80        return $this->root;
81    }
82
83    /**
84     * Is a root view model composed?
85     *
86     * @return bool
87     */
88    public function hasRoot()
89    {
90        return ($this->root instanceof Model);
91    }
92}
93