added default path detection
This commit is contained in:
parent
5a4973a36c
commit
51867226be
64
src/mite.php
64
src/mite.php
|
@ -37,6 +37,9 @@ class Mite {
|
|||
// initializes framework
|
||||
public function __construct($config = [])
|
||||
{
|
||||
// define base path as calling
|
||||
define('BASE', dirname(debug_backtrace()[0]['file']));
|
||||
|
||||
$this->init($config);
|
||||
}
|
||||
|
||||
|
@ -46,21 +49,47 @@ class Mite {
|
|||
self::$init = microtime(TRUE);
|
||||
|
||||
// sensible defaults
|
||||
$defaults = array
|
||||
(
|
||||
'index' => '/index.php',
|
||||
'debug' => 'FALSE',
|
||||
'paths' => array(
|
||||
'views' => '',
|
||||
'models' => ''
|
||||
)
|
||||
);
|
||||
$defaults = [
|
||||
'index' => '/index.php',
|
||||
'debug' => FALSE,
|
||||
'layout' => FALSE,
|
||||
'paths' => $this->paths($config['paths'])
|
||||
];
|
||||
|
||||
// merge in configuration overriding defaults
|
||||
self::$options = array_merge($defaults, $config);
|
||||
|
||||
// TODO: ack!!! forgot to update/retrieve settings from options
|
||||
self::$index = self::options('index');
|
||||
// self::$index = self::options('index');
|
||||
}
|
||||
|
||||
private function paths($config = [])
|
||||
{
|
||||
// application default paths
|
||||
$defaults = [
|
||||
'views' => '',
|
||||
'layouts' => '',
|
||||
'models' => ''
|
||||
];
|
||||
|
||||
// check views/ structure
|
||||
if(file_exists(BASE . '/views')) {
|
||||
// set views directory
|
||||
$defaults['views'] = BASE . '/views';
|
||||
|
||||
// check for layouts
|
||||
if(file_exists(BASE . '/views/layouts')) {
|
||||
// set layouts directory
|
||||
$defaults['layouts'] = BASE . '/views/layouts';
|
||||
}
|
||||
}
|
||||
|
||||
// check and set models directory
|
||||
if(file_exists(BASE . '/models')) {
|
||||
$defaults['models'] = BASE . '/models';
|
||||
}
|
||||
|
||||
return array_merge($defaults, $config['paths'] ?: []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,10 +287,19 @@ class Mite {
|
|||
// check if folder defined
|
||||
$dir = self::options('paths','views');
|
||||
|
||||
// update path
|
||||
$path = $dir ? "{$dir}/{$template}" : "{$template}";
|
||||
// use layout file
|
||||
if(file_exists("{$dir}/layouts/index.layout.php")) {
|
||||
|
||||
include($path);
|
||||
$content = $dir ? "{$dir}/{$template}" : "{$template}";
|
||||
|
||||
include("{$dir}/layouts/index.layout.php");
|
||||
|
||||
} else {
|
||||
// determine path to view template
|
||||
$path = $dir ? "{$dir}/{$template}" : "{$template}";
|
||||
|
||||
include($path);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
|
|
Loading…
Reference in New Issue