added default path detection
This commit is contained in:
parent
5a4973a36c
commit
51867226be
58
src/mite.php
58
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,
|
||||||
'paths' => array(
|
'layout' => FALSE,
|
||||||
'views' => '',
|
'paths' => $this->paths($config['paths'])
|
||||||
'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,11 +287,20 @@ 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
|
||||||
|
if(file_exists("{$dir}/layouts/index.layout.php")) {
|
||||||
|
|
||||||
|
$content = $dir ? "{$dir}/{$template}" : "{$template}";
|
||||||
|
|
||||||
|
include("{$dir}/layouts/index.layout.php");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// determine path to view template
|
||||||
$path = $dir ? "{$dir}/{$template}" : "{$template}";
|
$path = $dir ? "{$dir}/{$template}" : "{$template}";
|
||||||
|
|
||||||
include($path);
|
include($path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
* Error Handling and Logging
|
* Error Handling and Logging
|
||||||
|
|
Loading…
Reference in New Issue