if (php_sapi_name() !== "cli") { error_log('Error: The CLI interface is not being called from the command line.'); exit(1); } if (!defined('ENV')) { error_log('Error: ENV is not defined'); exit(1); } define('DEV_ENV', 'dev'); define('TEST_ENV', 'test'); define('DIST_ENV', 'dist'); define('DEV', ENV === DEV_ENV); // Create the dependency injector for the Phalcon framework $di = new DI(); $di->setShared('config', function () { $config = (require __DIR__ . "/config/config.php"); return $config; }); $config = $di->get('config'); if (!file_exists($config->path->tmpDir)) { mkdir($config->path->tmpDir); } // Setup composer autoloading so that it doesn't need to be specified in each Module require_once $config->path->composerDir . 'autoload.php'; // Configure essential services require $config->path->configDir . 'services.php'; $di = DI::getDefault(); $console = new WebirdConsole($di); // Inject the console back into the DI to enabled it to handle batch tasks inside of a task $di->setShared('console', $console); $console->registerModules(['cli' => ['className' => 'Webird\\Cli\\Module']]); if (DEV) {
// Using the CLI factory default services container $di = new CliDI(); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__))); $config = (include APPLICATION_PATH . '/config/config.php'); /** * Register the autoloader and tell it to register the tasks directory */ $loader = new \Phalcon\Loader(); $loader->registerNamespaces($config->namespaces->toArray()); $loader->register(); $di->set('config', $config); $di->setShared('db', function () use($config) { $dbConfig = $config->database->toArray(); $adapter = $dbConfig['adapter']; unset($dbConfig['adapter']); $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter; return new $class($dbConfig); }); // Create a console application $console = new ConsoleApp(); $console->setDI($di); /** * Process the console arguments */ $arguments = array(); foreach ($argv as $k => $arg) { if ($k == 1) { $arguments['task'] = $arg; } elseif ($k == 2) { $arguments['action'] = $arg;