/** @param options { folder: <template folder> control_folder: <control folder> instance_vars: <vars avaiable as '$instance[]' in templates> } */ function __construct($options = []) { //++ resolve template folder { if (!$options['folder']) { # attempt to find template folder at first file level, or at one higher $first_file = \Grithin\Reflection::firstFileExecuted(); $options['folder'] = dirname($first_file) . '/template/'; if (!is_dir($options['folder'])) { $options['folder'] = dirname($first_file) . '/../template/'; } } $options['folder'] = realpath($options['folder']) . '/'; if (!$options['folder']) { throw new \Exception('View folder doesn\'t exist'); } //++ } # resolve control folder if (!$options['control_folder']) { $options['control_folder'] = realpath($options['folder'] . '../control'); } $this->helpers = ['template' => $this]; if ($options['helpers']) { $this->helpers = array_merge($this->helpers, $options['helpers']); } $this->options = $options; $this->url_path = substr($_SERVER['REQUEST_URI'], 1); //request uri always starts with '/' }
function __construct($options = []) { if (!$options['folder']) { $firstFile = \Grithin\Reflection::firstFileExecuted(); $options['folder'] = dirname($firstFile) . '/control/'; } if (!is_dir($options['folder'])) { throw new \Exception('Control folder does not exist'); } $this->options = $options; }