ZF\Console\Application::__construct PHP Method

__construct() public method

Creates a RouteCollection and populates it with the $routes provided. Sets the banner to call showVersion(). If no help command is defined, defines one. If no version command is defined, defines one.
public __construct ( string $name, string $version, array | Traversabl\Traversable $routes, Zend\Console\Adapter\AdapterInterface $console = null, ZF\Console\DispatcherInterface $dispatcher = null )
$name string Application name
$version string Application version
$routes array | Traversabl\Traversable Routes/route specifications to use for the application
$console Zend\Console\Adapter\AdapterInterface Console adapter to use within the application
$dispatcher ZF\Console\DispatcherInterface Configured dispatcher mapping routes to callables
    public function __construct($name, $version, $routes, Console $console = null, DispatcherInterface $dispatcher = null)
    {
        if (!is_array($routes) && !$routes instanceof Traversable) {
            throw new InvalidArgumentException('Routes must be provided as an array or Traversable object');
        }
        $this->name = $name;
        $this->version = $version;
        if (null === $console) {
            $console = DefaultConsole::getInstance();
        }
        $this->console = $console;
        if (null === $dispatcher) {
            $dispatcher = new Dispatcher();
        }
        $this->dispatcher = $dispatcher;
        $this->routeCollection = $routeCollection = new RouteCollection();
        $this->setRoutes($routes);
        $this->banner = [$this, 'showVersion'];
        if (!$routeCollection->hasRoute('help')) {
            $this->setupHelpCommand($routeCollection, $dispatcher);
        }
        if (!$routeCollection->hasRoute('version')) {
            $this->setupVersionCommand($routeCollection, $dispatcher);
        }
        if (!$routeCollection->hasRoute('autocomplete')) {
            $this->setupAutocompleteCommand($routeCollection, $dispatcher);
        }
    }

Usage Example

Example #1
0
 public function __construct()
 {
     $routes = [['name' => '<config> <output_file> [--strip]', 'short_description' => "Generate class cache based on <config> file into <output_file>.", 'handler' => [$this, 'generateDump']]];
     parent::__construct('Cache dumper', 1.0, $routes, Console::getInstance());
     $this->removeRoute('autocomplete');
     $this->removeRoute('help');
     $this->removeRoute('version');
 }
All Usage Examples Of ZF\Console\Application::__construct