Fix potential memory leak on controller load in Template constructor

This commit is contained in:
Giuseppe Criscione 2019-04-26 23:21:47 +02:00
parent 1dcd0f3391
commit 0a7df298f3
2 changed files with 17 additions and 18 deletions

View File

@ -197,6 +197,8 @@ class Formwork
$resource = $this->router->dispatch(); $resource = $this->router->dispatch();
$resource->template()->loadController();
if (is_null($this->site->currentPage())) { if (is_null($this->site->currentPage())) {
$this->site->setCurrentPage($resource); $this->site->setCurrentPage($resource);
} }

View File

@ -89,7 +89,6 @@ class Template
$this->name = $template; $this->name = $template;
$this->page = $page; $this->page = $page;
$this->vars = $this->defaults(); $this->vars = $this->defaults();
$this->loadController();
} }
/** /**
@ -155,26 +154,10 @@ class Template
ob_end_flush(); ob_end_flush();
} }
/**
* Return an array containing the default data
*
* @return array
*/
protected function defaults()
{
return array(
'params' => Formwork::instance()->router()->params(),
'site' => Formwork::instance()->site(),
'page' => $this->page
);
}
/** /**
* Load template controller if exists * Load template controller if exists
*
* @return string|null
*/ */
protected function loadController() public function loadController()
{ {
if ($this->rendering) { if ($this->rendering) {
throw new RuntimeException(__METHOD__ . ' not allowed while rendering'); throw new RuntimeException(__METHOD__ . ' not allowed while rendering');
@ -188,6 +171,20 @@ class Template
} }
} }
/**
* Return an array containing the default data
*
* @return array
*/
protected function defaults()
{
return array(
'params' => Formwork::instance()->router()->params(),
'site' => Formwork::instance()->site(),
'page' => $this->page
);
}
/** /**
* Get Assets instance * Get Assets instance
* *