A Zend Framework library and skeleton module for creating cli modules.
Add following to your composer.json file
{
"repositories": [
{
"type": "git",
"url": "https://github.com/bvanderstee/zf-cli"
}
],
"require-dev": {
"bvanderstee/zf-cli": "dev-master"
}
}
You can check the ../vendor/bvanderstee/zf-cli/application
folder for a skeleton cli module.
You can check the ../vendor/bvanderstee/zf-cli/bin/script.php
for a skeleton script.php file
Add following code to your Bootstrap.php file
protected function _initCli()
{
if(PHP_SAPI == 'cli') {
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');
$front->setRouter(new ZFCli_Controller_Router_Cli());
$front->setRequest(new Zend_Controller_Request_Simple());
$front->setDefaultModule('cli');
$error = new Zend_Controller_Plugin_ErrorHandler(array(
'module' => 'cli',
'controller' => 'error',
'action' => 'error'
));
}
}
Check out the repositry or download the zip. Add the cli
module to your modules folder.
Add following code to your Bootstrap.php file
protected function _initCli()
{
if(PHP_SAPI == 'cli') {
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');
$front->setRouter(new ZFCli_Controller_Router_Cli());
$front->setRequest(new Zend_Controller_Request_Simple());
$front->setDefaultModule('cli');
$error = new Zend_Controller_Plugin_ErrorHandler(array(
'module' => 'cli',
'controller' => 'error',
'action' => 'error'
));
}
}
Add this autoloaderNamespaces[] = "ZFCli_"
to your application.ini file.
php bin/script.php controller action
php bin/script.php cli index
will output 'success'.