Skip to content

Commit

Permalink
newskel
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Nov 3, 2017
1 parent 5a156a3 commit 6a56da1
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions lib/lib.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Octo;

use function call_user_func_array;
use function func_get_args;
use Illuminate\Support\Debug\Dumper;
use function is_null;
Expand Down Expand Up @@ -2461,17 +2462,68 @@ function systemBoot($dir = null)
return call_user_func_array('\\Octo\\maker', $args);
});

$app->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 = "<h1><i class='fa fa-warning fa-2x'></i> Some errors occured</h1>";
$html .= "<h3>Please chmod 0777 these directories :</h3>";
$html .= "<ul>";

foreach ($errors as $error) {
$html .= "<li>" . realpath($error) . "</li>";
}

$html .= "</ul>";

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) {
Expand Down

0 comments on commit 6a56da1

Please sign in to comment.