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
|
// initializes framework
|
||||||
public function __construct($config = [])
|
public function __construct($config = [])
|
||||||
{
|
{
|
||||||
|
// define base path as calling
|
||||||
|
define('BASE', dirname(debug_backtrace()[0]['file']));
|
||||||
|
|
||||||
$this->init($config);
|
$this->init($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,21 +49,47 @@ class Mite {
|
||||||
self::$init = microtime(TRUE);
|
self::$init = microtime(TRUE);
|
||||||
|
|
||||||
// sensible defaults
|
// sensible defaults
|
||||||
$defaults = array
|
$defaults = [
|
||||||
(
|
'index' => '/index.php',
|
||||||
'index' => '/index.php',
|
'debug' => FALSE,
|
||||||
'debug' => 'FALSE',
|
'layout' => FALSE,
|
||||||
'paths' => array(
|
'paths' => $this->paths($config['paths'])
|
||||||
'views' => '',
|
];
|
||||||
'models' => ''
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// merge in configuration overriding defaults
|
// merge in configuration overriding defaults
|
||||||
self::$options = array_merge($defaults, $config);
|
self::$options = array_merge($defaults, $config);
|
||||||
|
|
||||||
// TODO: ack!!! forgot to update/retrieve settings from options
|
// 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
|
// check if folder defined
|
||||||
$dir = self::options('paths','views');
|
$dir = self::options('paths','views');
|
||||||
|
|
||||||
// update path
|
// use layout file
|
||||||
$path = $dir ? "{$dir}/{$template}" : "{$template}";
|
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