Created
September 11, 2014 01:54
-
-
Save kjdev/956c7837d7fd50c45f12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Using the CLI factory default services container | |
$di = new \Phalcon\DI\FactoryDefault\Cli; | |
// Register the autoloader and tell it to register the tasks directory | |
$loader = new \Phalcon\Loader; | |
$loader->registerDirs(array(dirname(__FILE__) . '/tasks'))->register(); | |
// Create a console application | |
$console = new \Phalcon\Cli\Console; | |
$console->setDI($di); | |
// Create a console application routing | |
$di->setShared('router', function() { | |
$router = new \Phalcon\Cli\Router(true); | |
$router->add('world', array( | |
'task' => 'main', | |
'action' => 'hello', | |
'params' => array('WORLD', '###') | |
)); | |
return $router; | |
}); | |
try { | |
$console->setArgument($argv)->handle(); | |
} catch (\Phalcon\Exception $e) { | |
echo $e->getMessage(), PHP_EOL; | |
exit(255); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class echoTask extends \Phalcon\CLI\Task | |
{ | |
public function mainAction() | |
{ | |
echo "echoMainAction\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php cli.php | |
mainAction | |
$ php cli.php main | |
mainAction | |
$ php cli.php main hello | |
Hello ! | |
$ php cli.php main hello world @ | |
Hello world@ | |
$ php cli.php echo | |
echoMainAction | |
$ php cli.php world | |
Hello WORLD### | |
$ php cli.php --strtoupper main hello world | |
HELLO WORLD! | |
$ php cli.php -u main hello world | |
HELLO WORLD! | |
$ php cli.php main hello world --strtolower | |
hello world! | |
$ php cli.php main -l hello world | |
hello world! | |
$ php cli.php main hello world --string=hoge | |
Hello world!hoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class mainTask extends \Phalcon\CLI\Task | |
{ | |
public function mainAction() | |
{ | |
echo "mainAction\n"; | |
} | |
public function helloAction($world = "", $symbol = "!") | |
{ | |
$retval = "Hello " . $world . $symbol; | |
$options = $this->dispatcher->getOptions(); | |
if (isset($options['strtoupper']) || isset($options['u'])) { | |
$retval = strtoupper($retval); | |
} | |
if (isset($options['strtolower']) || isset($options['l'])) { | |
$retval = strtolower($retval); | |
} | |
if (isset($options['string'])) { | |
$retval .= $options['string']; | |
} | |
echo $retval, PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment