public function testDispatcher()
 {
     $di = new \Phalcon\DI\FactoryDefault\CLI();
     $di->set('data', function () {
         return "data";
     });
     $dispatcher = new \Phalcon\CLI\Dispatcher();
     $dispatcher->setDI($di);
     $dispatcher->dispatch();
     $this->assertEquals($dispatcher->getTaskName(), 'main');
     $this->assertEquals($dispatcher->getTaskClass(), 'MainTask');
     $this->assertEquals($dispatcher->getActionName(), 'main');
     $this->assertEquals($dispatcher->getParams(), array());
     $this->assertEquals($dispatcher->getReturnedValue(), 'mainAction');
     $dispatcher->setTaskName('echo');
     $dispatcher->dispatch();
     $this->assertEquals($dispatcher->getTaskName(), 'echo');
     $this->assertEquals($dispatcher->getActionName(), 'main');
     $this->assertEquals($dispatcher->getParams(), array());
     $this->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction');
     $dispatcher->setTaskName('main');
     $dispatcher->setActionName('hello');
     $dispatcher->dispatch();
     $this->assertEquals($dispatcher->getTaskName(), 'main');
     $this->assertEquals($dispatcher->getActionName(), 'hello');
     $this->assertEquals($dispatcher->getParams(), array());
     $this->assertEquals($dispatcher->getReturnedValue(), 'Hello !');
     $dispatcher->setActionName('hello');
     $dispatcher->setParams(array('World', '######'));
     $dispatcher->dispatch();
     $this->assertEquals($dispatcher->getTaskName(), 'main');
     $this->assertEquals($dispatcher->getActionName(), 'hello');
     $this->assertEquals($dispatcher->getParams(), array('World', '######'));
     $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World######');
     // testing namespace
     try {
         $dispatcher->setDefaultNamespace('Dummy\\');
         $dispatcher->setTaskName('main');
         $dispatcher->setActionName('hello');
         $dispatcher->setParams(array('World'));
         $dispatcher->dispatch();
         $this->assertEquals($dispatcher->getTaskName(), 'main');
         $this->assertEquals($dispatcher->getActionName(), 'hello');
         $this->assertEquals($dispatcher->getParams(), array('World'));
         $this->assertEquals($dispatcher->getReturnedValue(), 'Hello World!');
     } catch (Exception $e) {
         $this->assertEquals($e->getMessage(), 'Dummy\\MainTask handler class cannot be loaded');
     }
 }
Beispiel #2
0
 /**
  *
  * Register the services here to make them module-specific
  *
  */
 public function registerServices($di)
 {
     // get bootstrap obj
     $bootstrap = $di->get('bootstrap');
     // get config class name
     $confClass = $bootstrap->getConfClass();
     // module config
     $mConfPath = __DIR__ . '/confs/' . PHALCON_ENV . '.' . PHALCON_CONF_TYPE;
     if (!is_file($mConfPath)) {
         throw new \Phalcon\Config\Exception("Module config file not exist, file position: {$mConfPath}");
     }
     if (PHALCON_CONF_TYPE == 'ini') {
         $mConfig = new $confClass($mConfPath);
     } else {
         if (PHALCON_CONF_TYPE == 'php') {
             $mConfig = new $confClass(require_once $mConfPath);
         }
     }
     // global config
     $gConfig = $di->get('config');
     // merge module config and global config, module's will override global's
     $gConfig->merge($mConfig);
     // set config back
     $di->set('config', $gConfig);
     // Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\CLI\Dispatcher();
         $dispatcher->setDefaultNamespace("BullSoft\\Sample\\Tasks\\");
         return $dispatcher;
     });
 }
Beispiel #3
0
 public function testIssue787()
 {
     $di = new \Phalcon\DI\FactoryDefault\CLI();
     $di->setShared('dispatcher', function () use($di) {
         $dispatcher = new Phalcon\CLI\Dispatcher();
         $dispatcher->setDI($di);
         return $dispatcher;
     });
     $console = new \Phalcon\CLI\Console();
     $console->setDI($di);
     $console->handle(array('task' => 'issue787', 'action' => 'main'));
     $this->assertTrue(class_exists('Issue787Task'));
     $actual = Issue787Task::$output;
     $expected = "beforeExecuteRoute\ninitialize\n";
     $this->assertEquals($actual, $expected);
 }
    die(PHP_EOL . PHP_EOL);
}
error_reporting(E_ALL | E_NOTICE);
if (!extension_loaded('phalcon')) {
    throw new Exception("Phalcon extension is required");
}
$params = $argv;
$file = array_shift($argv);
$task = array_shift($argv);
define('APP_ROOT', __DIR__ . '/app');
$loader = new Phalcon\Loader();
$loader->registerNamespaces(['ApiDocs' => APP_ROOT]);
$loader->register();
$di = new Phalcon\DI\FactoryDefault\CLI();
$di->setShared('dispatcher', function () use($di) {
    $dispatcher = new Phalcon\CLI\Dispatcher();
    $dispatcher->setDI($di);
    $dispatcher->setDefaultNamespace('ApiDocs\\Tasks');
    return $dispatcher;
});
$di->setShared('modelsManager', function () {
    return new Phalcon\Mvc\Model\Manager();
});
$di->setShared('db', function () use($di) {
    $connection = new Phalcon\Db\Adapter\Pdo\Mysql((array) $di->get('config')->db);
    return $connection;
});
$di->setShared('config', function () {
    return new Phalcon\Config(require APP_ROOT . '/config/config.php');
});
$console = new Phalcon\CLI\Console();
<?php

$di = new Phalcon\DI();
$dispatcher = new Phalcon\CLI\Dispatcher();
$dispatcher->setDI($di);
$dispatcher->setTaskName('posts');
$dispatcher->setActionName('index');
$dispatcher->setParams(array());
$handle = $dispatcher->dispatch();
Beispiel #6
0
 * Last-Updated: Wed Nov 27 12:10:20 2013 (+0800)
 *           By: Gu Weigang
 *     Update #: 27
 * 
 */
/* Change Log:
 * 
 * 
 */
/* This program is part of "Baidu Darwin PHP Software"; you can redistribute it and/or
 * modify it under the terms of the Baidu General Private License as
 * published by Baidu Campus.
 * 
 * You should have received a copy of the Baidu General Private License
 * along with this program; see the file COPYING. If not, write to
 * the Baidu Campus NO.10 Shangdi 10th Street Haidian District, Beijing The Peaple's
 * Republic of China, 100085.
 */
/* Code: */
require $system . "/loads/default.php";
$di->set('router', function () {
    $router = new \Phalcon\CLI\Router();
    return $router;
});
$di->set('dispatcher', function () use($di) {
    $dispatcher = new Phalcon\CLI\Dispatcher();
    $dispatcher->setDI($di);
    return $dispatcher;
});
$application->registerModules($config->cli_module->toArray());
/* default-cli.php ends here */
Beispiel #7
0
 } else {
     $di = new \Phalcon\DI\FactoryDefault\CLI();
 }
 //Setting MongoDB
 $di->set('mongo', function () {
     $mongo = new MongoClient();
     return $mongo->selectDb("ppro");
 }, true);
 //Registering the collectionManager service
 $di->set('collectionManager', function () {
     return new Phalcon\Mvc\Collection\Manager();
 }, true);
 //Setting Router
 if (PHP_SAPI == 'cli') {
     $di->set('dispatcher', function () {
         $dispatcher = new Phalcon\CLI\Dispatcher();
         $dispatcher->setDefaultNamespace('Notnull\\DailyNews\\Tasks');
         return $dispatcher;
     });
 }
 //Setting Router
 if (PHP_SAPI != 'cli') {
     $di->set('router', function () {
         return require __DIR__ . '/../app/config/routes.php';
     });
 }
 //Setting URL Helper
 $di->set('url', function () {
     $url = new Phalcon\Mvc\Url();
     $base = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '');
     $base .= "://";