Example #1
0
// include composer
include_once APPLICATION_PATH . "/vendor/autoload.php";
// Register the autoloader and tell it to register the tasks directory
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . '/tasks', APPLICATION_PATH . '/classes/'));
$loader->register();
// Creating the global path to the root folder
$di->set('path', function () {
    return array("root" => APPLICATION_PATH, "http" => "https://apretaste.com");
});
// Making the config global
$di->set('config', function () {
    return new ConfigIni(APPLICATION_PATH . '/configs/config.ini');
});
// Setup the database service
$config = $di->get('config');
$di->set('db', function () use($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config['database']['host'], "username" => $config['database']['user'], "password" => $config['database']['password'], "dbname" => $config['database']['database']));
});
// get the environment
$di->set('environment', function () use($config) {
    if (isset($config['global']['environment'])) {
        return $config['global']['environment'];
    } else {
        return "production";
    }
});
// Create a console application
$console = new ConsoleApp();
$console->setDI($di);
// Process the console arguments
<?php

use Phalcon\Di\FactoryDefault\Cli;
use Phalcon\Cli\Console;
require __DIR__ . '/../vendor/autoload.php';
$di = new Cli();
$di->get('dispatcher')->setNamespaceName('CaioFRAlmeida\\SoccerCompanyEvent\\Task');
$args = [];
if (isset($argv[1])) {
    $args['task'] = $argv[1];
}
$console = new Console($di);
try {
    $console->handle($args);
} catch (\Exception $e) {
    die('erro ao executar task');
}