Esempio n. 1
0
function cockpit($module = null)
{
    static $app;
    if (!$app) {
        $customconfig = [];
        if (file_exists(COCKPIT_CONFIG_PATH)) {
            $customconfig = Spyc::YAMLLoad(COCKPIT_CONFIG_PATH);
        }
        // load config
        $config = array_replace_recursive(['debug' => preg_match('/(localhost|::1|\\.dev)$/', $_SERVER['SERVER_NAME']), 'app.name' => 'Cockpit', 'base_url' => COCKPIT_BASE_URL, 'base_route' => COCKPIT_BASE_ROUTE, 'docs_root' => COCKPIT_DOCS_ROOT, 'session.name' => md5(__DIR__), 'sec-key' => 'c3b40c4c-db44-s5h7-a814-b4931a15e5e1', 'i18n' => 'en', 'database' => ["server" => "mongolite://" . (COCKPIT_STORAGE_FOLDER . "/data"), "options" => ["db" => "cockpitdb"]], 'memory' => ["server" => "redislite://" . (COCKPIT_STORAGE_FOLDER . "/data/cockpit.memory.sqlite"), "options" => []], 'paths' => ['#root' => COCKPIT_DIR, '#storage' => COCKPIT_STORAGE_FOLDER, '#data' => COCKPIT_STORAGE_FOLDER . '/data', '#cache' => COCKPIT_STORAGE_FOLDER . '/cache', '#tmp' => COCKPIT_STORAGE_FOLDER . '/tmp', '#modules' => COCKPIT_DIR . '/modules', '#uploads' => COCKPIT_DIR . '/uploads', '#config' => dirname(COCKPIT_CONFIG_PATH), 'assets' => COCKPIT_DIR . '/assets', 'site' => COCKPIT_DIR == COCKPIT_DOCS_ROOT ? COCKPIT_DIR : dirname(COCKPIT_DIR)]], is_array($customconfig) ? $customconfig : []);
        $app = new LimeExtra\App($config);
        $app["config"] = $config;
        // register paths
        foreach ($config['paths'] as $key => $path) {
            $app->path($key, $path);
        }
        // nosql storage
        $app->service('storage', function () use($config) {
            $client = new MongoHybrid\Client($config['database']['server'], $config['database']['options']);
            return $client;
        });
        // key-value storage
        $app->service('memory', function () use($config) {
            $client = new SimpleStorage\Client($config['memory']['server'], $config['memory']['options']);
            return $client;
        });
        // mailer service
        $app->service("mailer", function () use($app, $config) {
            $options = isset($config['mailer']) ? $config['mailer'] : [];
            $mailer = new \Mailer(isset($options["transport"]) ? $options['transport'] : 'mail', $options);
            return $mailer;
        });
        // set cache path
        $tmppath = $app->path('#tmp:');
        $app("cache")->setCachePath($tmppath);
        $app->renderer->setCachePath($tmppath);
        // i18n
        $app("i18n")->locale = isset($config['i18n']) ? $config['i18n'] : 'en';
        // load modules
        $app->loadModules([COCKPIT_DIR . '/modules/core', COCKPIT_DIR . '/modules/addons']);
        // load config global bootstrap
        if ($custombootfile = $app->path('config:bootstrap.php')) {
            include $custombootfile;
        }
        $app->trigger('cockpit.bootstrap');
    }
    // shorthand modules method call e.g. cockpit('regions:render', 'test');
    if (func_num_args() > 1) {
        $arguments = func_get_args();
        list($module, $method) = explode(':', $arguments[0]);
        array_splice($arguments, 0, 1);
        return call_user_func_array([$app->module($module), $method], $arguments);
    }
    return $module ? $app->module($module) : $app;
}
Esempio n. 2
0
function cockpit($module = null)
{
    static $app;
    if (!$app) {
        // load config
        $config = array_replace_recursive(['debug' => false, 'app.name' => 'Cockpit', 'base_url' => COCKPIT_BASE_URL, 'base_route' => COCKPIT_BASE_ROUTE, 'docs_root' => COCKPIT_DOCS_ROOT, 'session.name' => md5(__DIR__), 'sec-key' => 'c3b40c4c-db44-s5h7-a814-b4931a15e5e1', 'i18n' => 'en', 'database' => ["server" => "mongolite://" . (COCKPIT_DIR . "/storage/data"), "options" => ["db" => "cockpitdb"]], 'paths' => ['#root' => COCKPIT_DIR, 'storage' => COCKPIT_DIR . '/storage', '#backups' => COCKPIT_DIR . '/storage/backups', 'data' => COCKPIT_DIR . '/storage/data', 'cache' => COCKPIT_DIR . '/storage/cache', 'tmp' => COCKPIT_DIR . '/storage/cache/tmp', 'modules' => COCKPIT_DIR . '/modules', 'assets' => COCKPIT_DIR . '/assets', 'custom' => COCKPIT_DIR . '/custom', 'site' => COCKPIT_DIR == COCKPIT_DOCS_ROOT ? COCKPIT_DIR : dirname(COCKPIT_DIR)]], file_exists(COCKPIT_CONFIG_PATH) ? include COCKPIT_CONFIG_PATH : []);
        $app = new LimeExtra\App($config);
        $app["app.config"] = $config;
        // register paths
        foreach ($config['paths'] as $key => $path) {
            $app->path($key, $path);
        }
        // nosql storage
        $app->service('db', function () use($config) {
            $client = new MongoHybrid\Client($config['database']['server'], $config['database']['options']);
            return $client;
        });
        // key-value storage
        $app->service('memory', function () use($app) {
            $client = new RedisLite(sprintf("%s/cockpit.memory.sqlite", $app->path('data:')));
            return $client;
        });
        // mailer service
        $app->service("mailer", function () use($app, $config) {
            $options = isset($config['mailer']) ? $config['mailer'] : [];
            $mailer = new \Mailer(isset($options["transport"]) ? $options['transport'] : 'mail', $options);
            return $mailer;
        });
        // set cache path
        $tmppath = $app->path('cache:tmp');
        $app("cache")->setCachePath($tmppath);
        $app->renderer->setCachePath($tmppath);
        // i18n
        $app("i18n")->locale = isset($config['i18n']) ? $config['i18n'] : 'en';
        // load modules
        $app->loadModules([COCKPIT_DIR . '/modules/core', COCKPIT_DIR . '/modules/addons']);
        // load custom global bootstrap
        if ($custombootfile = $app->path('custom:bootstrap.php')) {
            include $custombootfile;
        }
        $app->trigger('cockpit.bootstrap');
    }
    // shorthand modules method call e.g. cockpit('regions:render', 'test');
    if (func_num_args() > 1) {
        $arguments = func_get_args();
        list($module, $method) = explode(':', $arguments[0]);
        array_splice($arguments, 0, 1);
        return call_user_func_array([$app->module($module), $method], $arguments);
    }
    return $module ? $app->module($module) : $app;
}
Esempio n. 3
0
function cockpit($module = null)
{
    static $app;
    if (!$app) {
        $config = (include __DIR__ . '/config.php');
        if (file_exists(__DIR__ . '/custom/config.php')) {
            $config = array_merge($config, include __DIR__ . '/custom/config.php');
        }
        $app = new LimeExtra\App($config);
        $app["app.config"] = $config;
        $app->path('#root', __DIR__);
        $app->path('storage', __DIR__ . '/storage');
        $app->path('backups', __DIR__ . '/storage/backups');
        $app->path('data', __DIR__ . '/storage/data');
        $app->path('cache', __DIR__ . '/storage/cache');
        $app->path('tmp', __DIR__ . '/storage/cache/tmp');
        $app->path('modules', __DIR__ . '/modules');
        $app->path('assets', __DIR__ . '/assets');
        $app->path('custom', __DIR__ . '/custom');
        $app->path('site', dirname(__DIR__));
        // nosql storage
        $app->service('db', function () use($config) {
            $client = new MongoHybrid\Client($config["database"]["server"], $config["database"]["options"]);
            return $client;
        });
        // key-value storage
        $app->service('memory', function () use($app) {
            $client = new RedisLite(sprintf("%s/cockpit.memory.sqlite", $app->path('data:')));
            return $client;
        });
        // mailer service
        $app->service("mailer", function () use($app, $config) {
            $options = isset($config['mailer']) ? $config['mailer'] : [];
            $mailer = new \Mailer(isset($options["transport"]) ? $options["transport"] : "mail", $options);
            return $mailer;
        });
        // set cache path
        $app("cache")->setCachePath("cache:tmp");
        // i18n
        $app("i18n")->locale = isset($config["i18n"]) ? $config["i18n"] : "en";
        // load modules
        $app->loadModules([__DIR__ . '/modules/core', __DIR__ . '/modules/addons']);
    }
    return $module ? $app->module($module) : $app;
}
Esempio n. 4
0
// boot cockpit
require_once __DIR__ . '/../../../bootstrap.php';
// PATHS + BASE DETECTION
// --------------------------------------------------------------
$SITE_DIR = dirname(COCKPIT_DIR);
$DOCS_ROOT = COCKPIT_DOCS_ROOT;
$BASE = trim(str_replace($DOCS_ROOT, '', $SITE_DIR), "/");
$BASE_URL = strlen($BASE) ? "/{$BASE}" : $BASE;
$BASE_ROUTE = $BASE_URL;
$FRONTEND_ROUTE = str_replace($BASE_URL, '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$TMP_PATH = $cockpit->path('cache:tmp');
// defines for quick access
define('AUTOPILOT_SITE_DIR', $SITE_DIR);
define('AUTOPILOT_DOCS_ROOT', $DOCS_ROOT);
define('AUTOPILOT_BASE_URL', $BASE_URL);
define('AUTOPILOT_BASE_ROUTE', $BASE_URL);
define('AUTOPILOT_TMP_PATH', $TMP_PATH);
$CONFIG = ['app.name' => 'autopilotFrontend', 'base_url' => $BASE_URL, 'base_route' => $BASE_ROUTE, 'route' => $FRONTEND_ROUTE, 'docs_root' => $DOCS_ROOT, 'session.name' => md5(__DIR__), 'sec-key' => 'c3b44ccc-dbf4-f5h7-a8r4-b4931a15e5e1', 'i18n' => 'en', 'debug' => false];
// load custom autopilot config for overrides
if ($customConfig = $cockpit->path('custom:autopilot/config.php')) {
    $CONFIG = array_merge($CONFIG, include $customConfig);
}
// init frontend app
$frontend = new LimeExtra\App($CONFIG);
$cockpit->module('autopilot')->frontend = $frontend;
// load frontend bootfile
include_once __DIR__ . '/frontend/bootstrap.php';
$frontend->trigger('autopilot.frontend.bootstrap');
// init cockpit wide before event
$cockpit->trigger('autopilot.frontend.before', [$frontend]);
$frontend->trigger('autopilot.frontend.init')->run();