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; }
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; }
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; }