3 && ctype_upper($name[3])) {
$name = lcfirst(substr($name, 3));
return $this->hasModule($name);
}
if ($this->hasModule($name)) {
return $this->modules[$name];
}
throw new \Exception('Invalid property.');
}
protected function __construct($config = null)
{
ExceptionHandler::register();
$this->addModule('router', new RouteCollection);
$this->addModule('templating', new TemplateEngine);
$this->addModule('config', new ConfigManager($config));
$this->templating->addFilter('json_decode');
$this->templating->addFilter('byte_symbol');
$this->templating->addFunction('byte_symbol');
$this->templating->addFunction('session_id');
$this->templating->addFunction('config', [$this->config, 'get']);
$this->templating->addFunction('route', [$this->router, 'url']);
echo sprintf(
'Running on commit %s on branch %3$s!',
self::gitCommitHash(true),
self::gitCommitHash(),
self::gitBranch()
);
}
public function __destruct()
{
ExceptionHandler::unregister();
}
public function debug(bool $mode): void
{
ExceptionHandler::debug($mode);
if ($this->hasTemplating) {
$this->templating->debug($mode);
}
}
public function addModule(string $name, $module): void
{
if ($this->hasModule($name)) {
throw new \Exception('This module has already been registered.');
}
$this->modules[$name] = $module;
}
public function hasModule(string $name): bool
{
return array_key_exists($name, $this->modules) && !is_null($this->modules[$name]);
}
}