Example #1
0
 public function testRouters()
 {
     $this->specify("CLI Router doesn't match the correct paths", function () {
         $di = new CliFactoryDefault();
         $di->set("data", function () {
             return "data";
         });
         $router = new Router();
         $router->handle([]);
         expect($router->getModuleName())->null();
         expect($router->getTaskName())->null();
         expect($router->getActionName())->null();
         expect($router->getParams())->equals([]);
         $router->handle(["task" => "main"]);
         expect($router->getModuleName())->null();
         expect($router->getTaskName())->equals("main");
         expect($router->getActionName())->null();
         expect($router->getParams())->equals([]);
         $router->handle(["task" => "echo"]);
         expect($router->getModuleName())->null();
         expect($router->getTaskName())->equals("echo");
         expect($router->getActionName())->null();
         expect($router->getParams())->equals([]);
         $router->handle(["task" => "main", "action" => "hello"]);
         expect($router->getModuleName())->null();
         expect($router->getTaskName())->equals("main");
         expect($router->getActionName())->equals("hello");
         expect($router->getParams())->equals([]);
         $router->handle(["task" => "main", "action" => "hello", "arg1", "arg2"]);
         expect($router->getModuleName())->null();
         expect($router->getTaskName())->equals("main");
         expect($router->getActionName())->equals("hello");
         expect($router->getParams())->equals(["arg1", "arg2"]);
         $router->handle(["module" => "devtools", "task" => "main", "action" => "hello", "arg1", "arg2"]);
         expect($router->getModuleName())->equals("devtools");
         expect($router->getTaskName())->equals("main");
         expect($router->getActionName())->equals("hello");
         expect($router->getParams())->equals(["arg1", "arg2"]);
         $router->handle(["module" => "devtools", "task" => "echo", "action" => "hello", "arg1", "arg2"]);
         expect($router->getModuleName())->equals("devtools");
         expect($router->getTaskName())->equals("echo");
         expect($router->getActionName())->equals("hello");
         expect($router->getParams())->equals(["arg1", "arg2"]);
     });
 }
Example #2
0
use Phalcon\Di\FactoryDefault\Cli as CliDi;
use Phalcon\Cli\Console as ConsoleApp;
use Phalcon\Logger;
use Phalcon\Logger\Adapter\File as FileAdapter;
/**
 * Read auto-loader
 */
include __DIR__ . '/config/loader.php';
/**
 * Read the configuration
 */
$config = (include __DIR__ . '/config/config.php');
/**
 * Read the services
 */
$di = new CliDi();
include __DIR__ . '/config/services.php';
/**
 * Create a console application
 */
$console = new ConsoleApp($di);
$worker = new GearmanWorker();
$worker->setId(sha1(date("d.m.Y H:i:s")));
$worker->addServer('192.168.77.56', 4730);
$worker->addFunction("send_metrix_calc", function ($job) use(&$console, &$di) {
    $di->set('workerJob', new MetrixResponse($di, $job, new FileAdapter(__DIR__ . "/logs/workjob_" . date("d-m-Y") . ".log")));
    $arguments = json_decode($job->workload(), true);
    $console->setDi($di);
    $console->handle($arguments);
});
while ($worker->work()) {
<?php

use Phalcon\Di\FactoryDefault\Cli as FactoryDefault;
use Phalcon\Cli\Console as ConsoleApp;
define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');
/**
 * The FactoryDefault Dependency Injector automatically registers the services that
 * provide a full stack framework. These default services can be overidden with custom ones.
 */
$di = new FactoryDefault();
/**
 * Include general services
 */
include APP_PATH . '/config/services.php';
/**
 * Include cli environment specific services
 */
include APP_PATH . '/config/services_cli.php';
/**
 * Include Autoloader
 */
include APP_PATH . '/config/loader.php';
/**
 * Get config service for use in inline setup below
 */
$config = $di->getConfig();
/**
 * Create a console application
 */
$console = new ConsoleApp($di);
Example #4
0
<?php

use Phalcon\Di\FactoryDefault\Cli as CliDi;
use Phalcon\Cli\Console as ConsoleApp;
/**
 * Read the services
 */
$di = new CliDi();
/**
 * Include Services
 */
include __DIR__ . '/config/services.php';
/**
 * Call the autoloader service.  We don't need to keep the results.
 */
$di->getLoader();
/**
 * Get the configuration
 */
$config = $di->getConfig();
/**
 * Create a console application
 */
$console = new ConsoleApp($di);
/**
 * Process the console arguments
 */
$arguments = [];
foreach ($argv as $k => $arg) {
    if ($k == 1) {
        $arguments['task'] = $arg;
Example #5
0
<?php

use Phalcon\Di\FactoryDefault\Cli as CliDI;
use Phalcon\Cli\Console as ConsoleApp;
use Phalcon\Config\Adapter\Ini as ConfigIni;
// set the date to come in Spanish
setlocale(LC_TIME, "es_ES");
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__)));
// 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']));
});
<?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');
}
Example #7
0
 public function testCallActionMethod()
 {
     $this->specify("CLI Dispatcher's callActionMethod doesn't work as expected", function () {
         $di = new CliFactoryDefault();
         $dispatcher = new Dispatcher();
         $di->setShared("dispatcher", $dispatcher);
         $dispatcher->setDI($di);
         $mainTask = new \MainTask();
         $mainTask->setDI($di);
         expect($dispatcher->callActionMethod($mainTask, 'mainAction', []))->equals('mainAction');
         expect($dispatcher->callActionMethod($mainTask, 'helloAction', ['World']))->equals('Hello World!');
         expect($dispatcher->callActionMethod($mainTask, 'helloAction', ['World', '.']))->equals('Hello World.');
     });
 }
Example #8
0
 public function testArgumentOptions()
 {
     $this->specify("CLI Console doesn't work with options set in arguments", function () {
         $di = new CliFactoryDefault();
         $di->setShared('router', function () {
             $router = new Router(true);
             return $router;
         });
         $console = new Console();
         $console->setDI($di);
         $dispatcher = $console->getDI()->getShared('dispatcher');
         $console->setArgument(array('php', '-opt1', '--option2', '--option3=hoge', 'main', 'hello', 'World', '######'))->handle();
         expect($dispatcher->getTaskName())->equals('main');
         expect($dispatcher->getActionName())->equals('hello');
         expect($dispatcher->getParams())->equals(array('World', '######'));
         expect($dispatcher->getReturnedValue())->equals('Hello World######');
         expect($dispatcher->getOptions())->equals(array('opt1' => true, 'option2' => true, 'option3' => 'hoge'));
         $console->setArgument(array('php', 'main', '-opt1', 'hello', '--option2', 'World', '--option3=hoge', '######'))->handle();
         expect($dispatcher->getTaskName())->equals('main');
         expect($dispatcher->getActionName())->equals('hello');
         expect($dispatcher->getParams())->equals(array('World', '######'));
         expect($dispatcher->getReturnedValue())->equals('Hello World######');
         expect($dispatcher->getOptions())->equals(array('opt1' => true, 'option2' => true, 'option3' => 'hoge'));
     });
 }
Example #9
0
 /**
  * @return $this
  */
 public function createDependencies()
 {
     $dependency = new Cli();
     $dependency->set('db', function () {
         return $this->getDatabase();
     });
     $dependency->setShared('application', $this);
     $this->setDI($dependency);
     return $this;
 }