1. Go to this page and download the library: Download zfcampus/zf-console library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// config/routes.php
return array(
array(
'name' => 'self-update',
'description' => 'When executed via the Phar file, performs a self-update by querying
the package repository. If successful, it will report the new version.',
'short_description' => 'Perform a self-update of the script',
),
array(
'name' => 'build',
'route' => '<package> [--target=]',
'description' => 'Build a package, using <package> as the package filename, and --target
as the application directory to be packaged.',
'short_description' => 'Build a package',
'options_descriptions' => array(
'<package>' => 'Package filename to build',
'--target' => 'Name of the application directory to package; defaults to current working directory',
),
'defaults' => array(
'target' => getcwd(), // default to current working directory
),
'handler' => 'My\Builder',
),
);
$dispatcher = new ZF\Console\Dispatcher;
$dispatcher->map('some-command-name', $callable)
function (\ZF\Console\Route $route, \Zend\Console\Adapter\AdapterInterface $console) {
}
use My\SelfUpdate;
use Zend\Console\Console;
use ZF\Console\Application;
use ZF\Console\Dispatcher;
lfUpdate($version));
$dispatcher->map('build', 'My\Build');
$application = new Application(
'Builder',
VERSION,
namespace ZF\Console;
use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter;
interface DispatcherInterface
{
/**
* Map a command name to its handler.
*
* @param string $command
* @param callable|string $command A callable command, or a string service
* or class name to use as a handler.
* @return self Should implement a fluent interface.
*/
public function map($command, $callable);
/**
* Does the dispatcher have a handler for the given command?
*
* @param string $command
* @return bool
*/
public function has($command);
/**
* Dispatch a routed command to its handler.
*
* @param Route $route
* @param ConsoleAdapter $console
* @return int The exit status code from the command.
*/
public function dispatch(Route $route, ConsoleAdapter $console);
}
$application = new Application('App', 1.0, $routes, null, $dispatcher);
$serviceManager = new ServiceManager(/* ... */);
// use `zend-servicemanager` as container
$dispatcher = new Dispatcher($serviceManager);
$application = new Application('App', 1.0, $routes, null, $dispatcher);
use Zend\Console\Console;
use Zend\Console\ColorInterface as Color;
use ZF\Console\Application;
use ZF\Console\Dispatcher;
chdir(dirname(__DIR__));
$services->get('My\BuildModel');
$dispatcher = new Dispatcher();
$dispatcher->map('build', function ($route, $console) use ($buildModel) {
$opts = $route->getMatches();
$result = $buildModel->build($opts['package'], $opts['target']);
if (! $result) {
$console->writeLine('Error building package!', Color::WHITE, Color::RED);
return 1;
}
$console->writeLine('Finished building package ' . $opts['package'], Color::GREEN);
return 0;
});
$application = new Application(
'Builder',
VERSION,
array(
array(
'name' => 'build',
'route' => 'build <package> [--target=]',
'description' => 'Build a package, using <package> as the package filename, and --target
as the application directory to be packaged.',
'short_description' => 'Build a package',
'options_descriptions' => array(
'<package>' => 'Package filename to build',
'--target' => 'Name of the application directory to package; defaults to current working directory',
),
'defaults' => array(
'target' => getcwd(), // default to current working directory
),
),
),
Console::getInstance(),
$dispatcher
);
$exit = $application->run();
exit($exit);