Commit 541cb903 authored by Taylor Otwell's avatar Taylor Otwell

Refactor view class.

parent 55e8f0e3
...@@ -57,11 +57,6 @@ class View { ...@@ -57,11 +57,6 @@ class View {
list($this->module, $this->path, $this->view) = static::parse($view); list($this->module, $this->path, $this->view) = static::parse($view);
if ( ! file_exists($this->path.$this->view.EXT))
{
throw new \Exception("View [$view] does not exist.");
}
$this->compose(); $this->compose();
} }
...@@ -95,7 +90,7 @@ class View { ...@@ -95,7 +90,7 @@ class View {
if ( ! is_null($view = static::find_view_for_name($name, static::$composers[$module]))) if ( ! is_null($view = static::find_view_for_name($name, static::$composers[$module])))
{ {
return new static($view, $data); return new static($view, $data);
} }
} }
...@@ -145,7 +140,7 @@ class View { ...@@ -145,7 +140,7 @@ class View {
$view = substr($view, strpos($view, ':') + 2); $view = substr($view, strpos($view, ':') + 2);
} }
return array($module, $path, str_replace('.', '/', $view)); return array($module, $path, $view);
} }
/** /**
...@@ -211,23 +206,40 @@ class View { ...@@ -211,23 +206,40 @@ class View {
*/ */
public function get() public function get()
{ {
foreach ($this->data as &$data) $view = str_replace('.', '/', $this->view);
if ( ! file_exists($this->path.$view.EXT))
{ {
if ($data instanceof View or $data instanceof Response) throw new \Exception("View [$view] does not exist.");
{
$data = (string) $data;
}
} }
$this->get_sub_views();
extract($this->data, EXTR_SKIP); extract($this->data, EXTR_SKIP);
ob_start(); ob_start();
try { include $this->path.$this->view.EXT; } catch (\Exception $e) { Error::handle($e); } try { include $this->path.$view.EXT; } catch (\Exception $e) { Error::handle($e); }
return ob_get_clean(); return ob_get_clean();
} }
/**
* Evaluate all of the view and response instances that are bound to the view.
*
* @return void
*/
private function get_sub_views()
{
foreach ($this->data as &$data)
{
if ($data instanceof View or $data instanceof Response)
{
$data = (string) $data;
}
}
}
/** /**
* Add a view instance to the view data. * Add a view instance to the view data.
* *
...@@ -238,7 +250,7 @@ class View { ...@@ -238,7 +250,7 @@ class View {
*/ */
public function partial($key, $view, $data = array()) public function partial($key, $view, $data = array())
{ {
return $this->bind($key, static::make($view, $data)); return $this->bind($key, new static($view, $data));
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment