Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Apply formatting sooner in `lithium\net\http\Router::match` close #995. #1000

Closed
wants to merge 1 commit into from

4 participants

@jails
Collaborator

No description provided.

@jails jails Apply formatting sooner in `lithium\net\http\Router::match` close #995.
540c86f
@marcghorayeb

my saviour ! :+1:

@jails Can we merge that fix?

Collaborator

yup !

Collaborator

reopened in UnionOfRAD#1126

@jails jails closed this
@jails jails deleted the jails:bug/router-match branch
@nateabele
Owner

@jails Remind me, why was this closed?

@jails
Collaborator

I didn't closed it intentionnaly. Just cleaned up some branch on my own fork but looks like it also result to this PR closing.

@jails jails restored the jails:bug/router-match branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2013
  1. @jails

    Apply formatting sooner in `lithium\net\http\Router::match` close #995.

    jails authored
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 3 deletions.
  1. +5 −3 net/http/Route.php
  2. +15 −0 tests/cases/net/http/RouterTest.php
View
8 net/http/Route.php
@@ -280,6 +280,11 @@ public function match(array $options = array(), $context = null) {
if (!$options = $this->_matchKeys($options)) {
return false;
}
+ foreach ($options as $key => $value) {
+ if (isset($this->_config['formatters'][$key])) {
+ $options[$key] = $this->_config['formatters'][$key]($value);
+ }
+ }
foreach ($this->_subPatterns as $key => $pattern) {
if (isset($options[$key]) && !preg_match("/^{$pattern}$/", $options[$key])) {
return false;
@@ -385,9 +390,6 @@ protected function _write($options, $defaults) {
continue;
}
}
- if (isset($this->_config['formatters'][$key])) {
- $value = $this->_config['formatters'][$key]($value);
- }
if ($value === null) {
$template = str_replace("/{$rpl}", '', $template);
continue;
View
15 tests/cases/net/http/RouterTest.php
@@ -811,6 +811,21 @@ public function testRouteFormatters() {
$this->assertEqual(array('args', 'controller'), array_keys($formatters));
}
+ public function testRouteFormattersAppliedOnMatch() {
+ Router::reset();
+ Router::connect('/{:controller:lists}/{:action:add}');
+ $this->assertIdentical(
+ '/lists/add',
+ Router::match(array('controller' => 'lists', 'action' => 'add'))
+ );
+
+ Router::connect('/lists/{:action:add}', array('controller' => 'lists'));
+ $this->assertIdentical(
+ '/lists/add',
+ Router::match(array('controller' => 'lists', 'action' => 'add'))
+ );
+ }
+
public function testRouteModifiers() {
$modifiers = Router::modifiers();
$this->assertEqual(array('args', 'controller'), array_keys($modifiers));
Something went wrong with that request. Please try again.