예제 #1
0
 public function __construct($argv)
 {
     //Using the CLI factory default services container
     $di = new CliDI();
     //Register the autoloader and tell it to register the tasks directory
     include __DIR__ . '/../config/loader.php';
     //Load the configuration file
     $config = (include __DIR__ . '/../config/config.php');
     $di->set('config', $config);
     include __DIR__ . '/../config/services.php';
     //Create a console application
     $console = new ConsoleApp();
     $console->setDI($di);
     //Process the console arguments
     foreach ($argv as $k => $arg) {
         if ($k == 1) {
             $this->arguments['task'] = $arg;
         } elseif ($k == 2) {
             $this->arguments['action'] = $arg;
         } elseif ($k >= 3) {
             $this->params[] = $arg;
         }
     }
     if (count($this->params) > 0) {
         $this->arguments['params'] = $this->params;
     }
     $this->console = $console;
 }
예제 #2
0
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
// Using the CLI factory default services container
$di = new CliDI();
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
/**
 * Register the autoloader and tell it to register the tasks directory
 */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . '/tasks', APPLICATION_PATH . '/models', APPLICATION_PATH . '/classes'));
$loader->register();
// Load the configuration file (if any)
if (is_readable(APPLICATION_PATH . '/config/config.php')) {
    $config = (include APPLICATION_PATH . '/config/config.php');
    $di->set('config', $config);
}
// Create a console application
$console = new ConsoleApp();
$console->setDI($di);
//Setup the database service
$di->set('db', function () use($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
});
/**
 * Process the console arguments
 */
$arguments = array();
foreach ($argv as $k => $arg) {
예제 #3
0
 /**
  * CLI 模式下的 DI 配置
  *
  * @param CLI $di
  */
 protected function cliDI(CLI $di)
 {
     global $argv;
     $di->set('router', function () use($di, $argv) {
         $router = new CLIRouter();
         $router->setDI($di);
         return $router;
     });
     $di->set('output', function () {
         return new ConsoleOutput();
     });
     $di->set('dispatcher', function () use($di, $argv) {
         $dispatcher = new CLIDispatcher();
         $dispatcher->setDI($di);
         $moduleName = array_shift($argv);
         $taskName = array_shift($argv);
         $actionName = 'main';
         if (strpos($taskName, ':') > 0) {
             @(list($taskName, $actionName) = preg_split("/:/", $taskName));
         }
         if ($moduleName) {
             $dispatcher->setTaskName(ucwords($taskName));
             $dispatcher->setActionName($actionName);
             $dispatcher->setParams($argv);
             if ($moduleName == '_current') {
                 $_appName = ucwords($this->getAppName());
                 $dispatcher->setNamespaceName("{$_appName}\\Tasks");
             } else {
                 $dispatcher->setNamespaceName("Eva\\{$moduleName}\\Tasks");
             }
         } else {
             $dispatcher->setTaskName('Main');
             $dispatcher->setParams($argv);
             $dispatcher->setNamespaceName("Eva\\EvaEngine\\Tasks");
         }
         return $dispatcher;
     });
 }
예제 #4
0
파일: cli.php 프로젝트: Pablo251/Kangoo
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
//Using the CLI factory default services container
$di = new CliDI();
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
/**
 * Register the autoloader and tell it to register the tasks directory
 */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . '/tasks', APPLICATION_PATH . '/models', APPLICATION_PATH . '/library'));
$loader->register();
// Load the configuration file (if any)
if (is_readable(APPLICATION_PATH . '/config/config.php')) {
    $config = (include APPLICATION_PATH . '/config/config.php');
    $di->set('config', $config);
}
$config = $di->get('config');
//Setup the database service
$di->set('db', function () use($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
});
$di->set('libaccess', function () use($config) {
    return new Mails();
});
/**
 * Loading routes from the routes.php file
 */
// $di->set('router', function() {
예제 #5
0
파일: cron.php 프로젝트: mpetcu/lime-juice
<?php

/**
 * @author: Mihai Petcu mihai.costin.petcu@gmail.com
 * @date: 10.10.2015
 */
use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
try {
    // Using the CLI factory default services container
    $di = new CliDI();
    // Define path to application directory
    defined('APP_PATH') || define('APP_PATH', realpath(dirname(__FILE__)));
    // Load necessary
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array(APP_PATH . '/tasks', APP_PATH . '/models', APP_PATH . '/library', APP_PATH . '/library/PHPExcel/Classes/'));
    $loader->register();
    // Load the conf
    if (is_readable(APP_PATH . '/config/config.php')) {
        $config = (include APP_PATH . '/config/config.php');
        $di->set('config', $config);
    }
    // Mongo connection
    $di->set('mongo', function () use($config) {
        if (!$config->mongo->user or !$config->mongo->pass) {
            $mongo = new MongoClient('mongodb://' . $config->mongo->host);
        } else {
            $mongo = new MongoClient("mongodb://" . $config->mongo->user . ":" . $config->mongo->pass . "@" . $config->mongo->host, array("db" => $config->mongo->dbname));
        }
        return $mongo->selectDb($config->mongo->dbname);
    }, false);
    // Load collection nanager
예제 #6
0
파일: cli.php 프로젝트: tresemece/monte
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
//Using the CLI factory default services container
$di = new CliDI();
// Define path to application directory
if (!defined('DIRS')) {
    define('DIRS', DIRECTORY_SEPARATOR);
}
if (!defined('ROOTFULLPATH')) {
    define('ROOTFULLPATH', dirname(__DIR__));
}
if (!defined('APPFULLPATH')) {
    define('APPFULLPATH', ROOTFULLPATH . DIRS . 'app');
}
if (!defined('AMBIENTE')) {
    define('AMBIENTE', 'DESARROLLO');
}
if (!defined('CONFIG_PATH')) {
    if (is_dir(APPFULLPATH . DIRS . 'config' . DIRS . AMBIENTE)) {
        define('CONFIG_PATH', APPFULLPATH . DIRS . 'config' . DIRS . AMBIENTE);
    } else {
        define('CONFIG_PATH', APPFULLPATH . DIRS . 'config');
    }
}
$conf = new \Phalcon\Config\Adapter\Ini(CONFIG_PATH . DIRS . "ini/config.ini");
if (!defined('SITESLUG')) {
    define('SITESLUG', $conf->site->slug);
}
/**
예제 #7
0
use Phalcon\Events\Manager as PhEventsManager;
use Phalcon\Logger as PhLogger;
use Phalcon\Logger\Adapter\File as PhLoggerFile;
use Phalcon\Logger\Formatter\Line as PhLoggerFormatter;
use Phalcon\Mvc\Model\Manager as PhModelsManager;
use Phalcon\Logger\Adapter\Database as PhLoggerDatabase;
ob_start();
try {
    if (!defined('ROOT_PATH')) {
        define('ROOT_PATH', dirname(dirname(__FILE__)));
    }
    require_once ROOT_PATH . '/cli/app/Migration.php';
    /**
     * Cli DI
     */
    $di = new PhCliDI();
    /**
     * CONFIG
     */
    $configFile = (require ROOT_PATH . '/conf/global.php');
    $config = new PhConfig($configFile);
    $di['config'] = $config;
    if (isset($config->app_debug)) {
        $debug = (bool) $config->app_debug;
    } else {
        $debug = false;
    }
    /**
     * AUTOLOADER
     */
    $dirs = [ROOT_PATH . '/cli/app/tasks'];
예제 #8
0
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) {
    class_alias('\\Webird\\Debug', '\\Dbg', true);
}
try {
    $console->handle(['module' => 'cli', 'defaultCmd' => 'server', 'params' => $argv]);
} catch (PhalconException $e) {
    error_log($e->getMessage());
    exit(255);
} catch (\Exception $e) {
    error_log($e->getMessage());
    exit($e->getCode());
예제 #9
0
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
$di = new CliDI();
$di->set('db', function () use($config) {
    $connection = new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
    return $connection;
});
예제 #10
0
파일: cli.php 프로젝트: sysatom/workflow
/*
 * This file is part of Workflow.
 *
 * (c) sysatom <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Phalcon\DI\FactoryDefault\CLI as CliDI;
use Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
// Composer AutoLoad
include __DIR__ . "/../vendor/autoload.php";
//使用CLI工厂类作为默认的服务容器
$di = new CliDI();
// 定义应用目录路径
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
// 注册类自动加载器
$loader = new \Phalcon\Loader();
$loader->registerDirs([APPLICATION_PATH . '/tasks']);
$loader->register();
// 加载配置文件
$config = (require APPLICATION_PATH . '/config/config.php');
$di->set('config', $config);
// Queue
$di->set('queue', function () use($di) {
    $config = $di->getShared('config');
    return new \Phalcon\Queue\Beanstalk\Extended(['host' => $config->queue->host, 'port' => $config->queue->port, 'prefix' => $config->queue->prefix]);
});
// 创建console应用
예제 #11
0
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI;
use Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
// 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();
<?php

/**
 * @author Patsura Dmitry <*****@*****.**>
 */
include_once __DIR__ . '/../vendor/autoload.php';
define('APPLICATION_PATH', realpath(__DIR__));
define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development');
use App\Console\Command\SettingsUpdate;
use App\Console\Application;
$config = (include APPLICATION_PATH . "/config/core.php");
$application = new \Phalcony\Application(APPLICATION_ENV, $config, \Phalcon\DI\FactoryDefault\CLI::getDefault());
$application->bootstrap();
$consoleApplication = new Application($application);
$consoleApplication->add(new SettingsUpdate());
$consoleApplication->run();