Where I can find example of using \Phalcon\Cli classes? It's looks very interesting.
|
Jun '13 |
3 |
970 |
1 |
Hi SliceOfLife, i think you can have a look at the dev tools github page :
https://github.com/phalcon/phalcon-devtools?source=cc
The' phalcon.php' file is the entry point of the application while all sources will be located under the 'scripts' directory You can also find the command used by the application under : 'scripts/Phalcon/Commands/Builtin'
There are some links with examples in other threads
https://forum.phalcon.io/discussion/114/cli-example- https://forum.phalcon.io/discussion/19/cli
Nice example, but I can't understand how to run a custom Task.
I wrote a console executable file:
#!/usr/bin/env php
<?php
error_reporting(E_ALL);
try {
$config = require __DIR__ . '/../app/config/config.php';
$loader = new \Phalcon\Loader();
$loader->registerDirs([
$config->application->tasksDir,
$config->application->pluginsDir,
$config->application->libraryDir,
$config->application->modelsDir,
])->register();
/**
* @var \Phalcon\DiInterface $di
*/
$di = require __DIR__ . '/../app/config/cli/di.php';
$di->set('config', $config);
$console = new \Phalcon\CLI\Console();
$console->setDI($di);
$console->handle($_SERVER['argv']);
} catch (\Phalcon\Exception $e) {
echo $e->getMessage() . "\n";
} catch (\PDOException $e){
echo $e->getMessage() . "\n";
}
If i run it from console without any parameters, the MainTask class and mainAction() exec. But if I run it with parameter "sessions", the mainAction of SessionsTask does not run (MainTask is executed again):
./console sessions
The SessionsTask.php and MainTask.php placed in one directory.
The way in which parameters are passed has changed in 1.1.0, more examples:
https://forum.phalcon.io/discussion/356/cli-args#C1672 https://forum.phalcon.io/discussion/372/phalcon-cli-apps-with-namespaces-in-phalcon-loader#C1606