Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #30 from zf2timo/feature/dispatch-interface
Browse files Browse the repository at this point in the history
Proposal: DispatcherInterface
  • Loading branch information
weierophinney committed Jul 11, 2016
2 parents dfb2635 + 80154a3 commit c4e4600
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Application
protected $debug = false;

/**
* @var Dispatcher
* @var DispatcherInterface
*/
protected $dispatcher;

Expand Down Expand Up @@ -84,14 +84,14 @@ class Application
* @param string $version Application version
* @param array|Traversable $routes Routes/route specifications to use for the application
* @param Console $console Console adapter to use within the application
* @param Dispatcher $dispatcher Configured dispatcher mapping routes to callables
* @param DispatcherInterface $dispatcher Configured dispatcher mapping routes to callables
*/
public function __construct(
$name,
$version,
$routes,
Console $console = null,
Dispatcher $dispatcher = null
DispatcherInterface $dispatcher = null
) {
if (! is_array($routes) && ! $routes instanceof Traversable) {
throw new InvalidArgumentException('Routes must be provided as an array or Traversable object');
Expand Down Expand Up @@ -131,7 +131,7 @@ public function __construct(
}

/**
* @return Dispatcher
* @return DispatcherInterface
*/
public function getDispatcher()
{
Expand Down Expand Up @@ -465,9 +465,9 @@ public function isBannerDisabledForUserCommands()
* Creates the route, and maps the command.
*
* @param RouteCollection $routeCollection
* @param Dispatcher $dispatcher
* @param DispatcherInterface $dispatcher
*/
protected function setupHelpCommand(RouteCollection $routeCollection, Dispatcher $dispatcher)
protected function setupHelpCommand(RouteCollection $routeCollection, DispatcherInterface $dispatcher)
{
$help = new HelpCommand($this);
$routeCollection->addRouteSpec([
Expand Down Expand Up @@ -503,9 +503,9 @@ protected function setupHelpCommand(RouteCollection $routeCollection, Dispatcher
* Creates the route, and maps the command.
*
* @param RouteCollection $routeCollection
* @param Dispatcher $dispatcher
* @param DispatcherInterface $dispatcher
*/
protected function setupVersionCommand(RouteCollection $routeCollection, Dispatcher $dispatcher)
protected function setupVersionCommand(RouteCollection $routeCollection, DispatcherInterface $dispatcher)
{
$routeCollection->addRouteSpec([
'name' => 'version',
Expand All @@ -531,9 +531,9 @@ protected function setupVersionCommand(RouteCollection $routeCollection, Dispatc
* Creates the route, and maps the command.
*
* @param RouteCollection $routeCollection
* @param Dispatcher $dispatcher
* @param DispatcherInterface $dispatcher
*/
protected function setupAutocompleteCommand(RouteCollection $routeCollection, Dispatcher $dispatcher)
protected function setupAutocompleteCommand(RouteCollection $routeCollection, DispatcherInterface $dispatcher)
{
$routeCollection->addRouteSpec([
'name' => 'autocomplete',
Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter;
use Zend\Console\ColorInterface as Color;

class Dispatcher
class Dispatcher implements DispatcherInterface
{
protected $commandMap = [];

Expand Down
24 changes: 24 additions & 0 deletions src/DispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
*/

namespace ZF\Console;

use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter;

interface DispatcherInterface
{
public function map($command, $callable);

/**
* Does the dispatcher have a handler for the given command?
*
* @param string $command
* @return bool
*/
public function has($command);

public function dispatch(Route $route, ConsoleAdapter $console);
}

0 comments on commit c4e4600

Please sign in to comment.