Skip to content

Commit

Permalink
Auto templating
Browse files Browse the repository at this point in the history
This feature allow Engine in View automatically set template by method
name and class name in following format: `class/method`. Use
`->autoTemplate()` before `run()` on Application.
  • Loading branch information
VeeeneX committed Aug 16, 2015
1 parent a90f71d commit 6df5541
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Application
*/
private $ApplicationConfig;

public $autoTemplate = false;

/**
* Constructor
* @param Config $Config Instance of Config must be given
Expand Down Expand Up @@ -79,6 +81,12 @@ public function run($callable, $params = array())
$Instance->ApplicationConfig = $this->ApplicationConfig;
$Instance->Param = (object) $params;

if ($this->autoTemplate) {
if ($Instance instanceof Presenter) {
$Instance->View->setTemplate(strtolower($controllerClass."/".$controllermethod));
}
}

$Rule->Instance = $Instance;
$this->Resolver->addRule($Rule);

Expand All @@ -96,4 +104,11 @@ public function run($callable, $params = array())
$this->Resolver->execute($callable, $params);
}
}

public function autoTemplate($bool = true)
{
$this->autoTemplate = $bool;

return $this;
}
}

0 comments on commit 6df5541

Please sign in to comment.