Esempio n. 1
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"]], 'memory' => ["server" => "redislite://" . (COCKPIT_DIR . "/storage/data/cockpit.memory.sqlite"), "options" => []], '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($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('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. 2
0
function cockpit($module = null)
{
    static $app;
    if (!$app) {
        $customconfig = [];
        // load custom config
        if (!defined('COCKPIT_CONFIG_PATH')) {
            $_sitedir = dirname(COCKPIT_DIR);
            $_configpath = $_sitedir . "/config/config." . (file_exists($_sitedir . "/config/config.php") ? 'php' : 'yaml');
            define('COCKPIT_CONFIG_PATH', $_configpath);
        }
        if (file_exists(COCKPIT_CONFIG_PATH)) {
            $customconfig = preg_match('/\\.yaml$/', COCKPIT_CONFIG_PATH) ? Spyc::YAMLLoad(COCKPIT_CONFIG_PATH) : (include 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', '#thumbs' => COCKPIT_STORAGE_FOLDER . '/thumbs', '#uploads' => COCKPIT_STORAGE_FOLDER . '/uploads', '#modules' => COCKPIT_DIR . '/modules', '#addons' => COCKPIT_DIR . '/addons', '#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(array_merge([COCKPIT_DIR . '/modules', COCKPIT_DIR . '/addons'], isset($config['loadmodules']) ? (array) $config['loadmodules'] : []));
        // 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. 3
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();