Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Issue #3358 - Fix for console router not accepting controller word as part of a route #4182

Closed
wants to merge 1 commit into from

3 participants

@robertboloc

Fix for issue #3358

@weierophinney weierophinney was assigned
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4182' into develop
Forward port #4182
61fa3ce
@ezk84

This fix violates the assumption that the defaults are fallback values; instead the defaults are being used to override any values entered at the console.

Here's a unit test to show this faulty behaviour:

// ZendTest/Mvc/Router/Console/SimpleTest.php
public function testMatchValuesOverrideDefaults()
{
    $defaults = array(
        'foo' => 'bar',
        'baz' => 'inga',
    );
    $foo = 'a value';

    $request = new ConsoleRequest(array('scriptname.php', $foo));
    $route = new Simple('<foo>', array(), $defaults);
    $match = $route->match($request);

    $this->assertInstanceOf('Zend\Mvc\Router\Console\RouteMatch', $match);
    // $foo should override the default value of 'bar'
    $this->assertEquals($foo, $match->getParam('foo'));
    // nothing overrode 'baz', so should still have the default value
    $this->assertEquals($defaults['baz'], $match->getParam('baz'));
}

The issue #3358 is caused not by the order in which defaults are overridden, but because Zend\Mvc\Router\Console\Simple turns matched literal console parameters into RouteMatch parameters (in the case of matched literal parameters, they get assigned the value true).

Now since controller is the RouteMatch parameter that ultimately determines the controller service name to dispatch to, when a literal console parameter is named controller the router will try to dispatch to a controller with service key true, which will, in all likelihood, not be available.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4182'
Close #4182
3284d65
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4182' into develop
Forward port #4182
1dbdb84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  library/Zend/Mvc/Router/Console/Simple.php
@@ -797,7 +797,7 @@ public function match(Request $request, $pathOffset = null)
return null; // there are extraneous params that were not consumed
}
- return new RouteMatch(array_merge($this->defaults, $matches));
+ return new RouteMatch(array_replace($matches, $this->defaults));
}
/**
View
14 tests/ZendTest/Mvc/Router/Console/SimpleTest.php
@@ -695,4 +695,18 @@ public function testFactory()
)
);
}
+
+ public function testMatchMergeOfTheDefaults()
+ {
+ $defaults = array(
+ 'controller' => 'Controller/Test',
+ );
+
+ $request = new ConsoleRequest(array('scriptname.php', 'foo', 'controller'));
+ $route = new Simple('foo controller', array(), $defaults);
+ $match = $route->match($request);
+
+ $this->assertInstanceOf('Zend\Mvc\Router\Console\RouteMatch', $match);
+ $this->assertEquals($defaults['controller'], $match->getParam('controller'));
+ }
}
Something went wrong with that request. Please try again.