diff --git a/lib/lib.php b/lib/lib.php index bda3947..0071781 100755 --- a/lib/lib.php +++ b/lib/lib.php @@ -1,6 +1,7 @@ register(function ($alias, $class, $args = []) use ($app) { + $app->init(function ($dir) { + $ini = parse_ini_file($dir . '/../.env'); + + defined('APPLICATION_ENV') || define('APPLICATION_ENV', isset($ini['APPLICATION_ENV']) ? $ini['APPLICATION_ENV'] : 'production'); + defined('SITE_NAME') || define('SITE_NAME', isset($ini['SITE_NAME']) ? $ini['SITE_NAME'] : 'project'); + + $root = realpath($dir . '/../'); + + $nameDir = Arrays::last(explode(DS, $root)); + + if (fnmatch('/' . $nameDir . '/*', $_SERVER['REQUEST_URI'])) { + define('FROM_ROOT', $nameDir); + } + + path("base", $root); + path("app", realpath($root . '/app')); + path('public', realpath($dir)); + + systemBoot($dir); + + $errors = []; + + if (!is_writable($dir . '/../app/storage/data')) { + $errors[] = $dir . '/../app/storage/data'; + } + + if (!is_writable($dir . '/../app/storage/cache')) { + $errors[] = $dir . '/../app/storage/cache'; + } + + if (!is_writable($dir . '/../app/storage/tmp')) { + $errors[] = $dir . '/../app/storage/tmp'; + } + + if (!empty($errors)) { + $html = "

Some errors occured

"; + $html .= "

Please chmod 0777 these directories :

"; + $html .= ""; + + view($html, 500, 'Octo Error Report'); + } + }); + + $app->register(function ($class, $args = []) use ($app) { if (is_object($args)) { $args = []; } $instance = maker($class, $args); - $app[$alias] = $instance; + $app[$class] = $instance; }); $app->apply(function (callable $callable) { - $callable(); + $app = App::create(); + + return call_user_func_array($callable, [$app]); }); $app->run(function ($namespace = 'App', $cli = false) {