Skip to content

Commit

Permalink
Make it possible to change Presenter views; closes #1479
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed Jul 29, 2016
1 parent 954ac2a commit 0edc9c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 14 additions & 3 deletions classes/presenter.php
Expand Up @@ -143,9 +143,21 @@ public function get_view()
/**
* Construct the View object
*/
protected function set_view()
public function set_view($view = null)
{
$this->_view instanceOf View or $this->_view = \View::forge($this->_view);
// construct a view object if needed
if (is_null($view))
{
$view = $this->_view;
$this->_view = null;
}
if ( ! $view instanceOf View)
{
$view = \View::forge($view, $this->_view);
}

// store the constructed object
$this->_view = $view;
}

/**
Expand Down Expand Up @@ -225,7 +237,6 @@ public function set($key, $value = null, $filter = null)
{
is_null($filter) and $filter = $this->_auto_filter;
$this->_view->set($key, $value, $filter);

return $this;
}

Expand Down
17 changes: 15 additions & 2 deletions classes/view.php
Expand Up @@ -108,10 +108,24 @@ public static function forge($file = null, $data = null, $auto_filter = null)
*/
public function __construct($file = null, $data = null, $filter = null)
{
if (is_object($data) === true)
// if data passed is contained in another view
if ($data instanceOf View)
{
// extract it
$this->local_filter =& $data->local_filter;
is_null($filter) and $filter = $data->auto_filter;
$this->data =& $data->data;
$data = null;
}

// for any other object
elseif (is_object($data) === true)
{
// see if we get can to the object properties
$data = get_object_vars($data);
}

// else it better by and array !
elseif ($data and ! is_array($data))
{
throw new \InvalidArgumentException('The data parameter only accepts objects and arrays.');
Expand Down Expand Up @@ -284,7 +298,6 @@ protected function get_data($scope = 'all')
{
$filter = array_key_exists($key, $rules) ? $rules[$key] : null;
$filter = is_null($filter) ? $auto_filter : $filter;

if ($filter)
{
if ($filter_closures and $value instanceOf \Closure)
Expand Down

0 comments on commit 0edc9c3

Please sign in to comment.