Skip to content

Commit

Permalink
Remove the header matching from Route::parse()
Browse files Browse the repository at this point in the history
This feature was very infrequently used to the point that many core team
members did not even know it existed. Removing it makes sense now that
custom route classes are well supported and easy to use.
  • Loading branch information
markstory committed Jul 16, 2014
1 parent 80066a2 commit b0e39c1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 65 deletions.
33 changes: 0 additions & 33 deletions src/Routing/Route/Route.php
Expand Up @@ -78,16 +78,6 @@ class Route {
*/
protected $_name = null;

/**
* HTTP header shortcut map. Used for evaluating header-based route expressions.
*
* @var array
*/
protected $_headerMap = [
'type' => 'content_type',
'server' => 'server_name'
];

/**
* List of connected extensions for this route.
*
Expand Down Expand Up @@ -283,29 +273,6 @@ public function parse($url) {
}
}

foreach ($this->defaults as $key => $val) {
$key = (string)$key;
if ($key[0] === '[' && preg_match('/^\[(\w+)\]$/', $key, $header)) {
if (isset($this->_headerMap[$header[1]])) {
$header = $this->_headerMap[$header[1]];
} else {
$header = 'http_' . $header[1];
}
$header = strtoupper($header);

$val = (array)$val;
$h = false;

foreach ($val as $v) {
if ($request->env($header) === $v) {
$h = true;
}
}
if (!$h) {
return false;
}
}
}
array_shift($route);
$count = count($this->keys);
for ($i = 0; $i <= $count; $i++) {
Expand Down
32 changes: 0 additions & 32 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -719,38 +719,6 @@ public function testMatchWithMultipleHttpMethodConditions() {
$this->assertEquals('/sample', $route->match($url));
}

/**
* Test that the [type] condition works.
*
* @return void
*/
public function testParseWithContentTypeCondition() {
$_SERVER['REQUEST_METHOD'] = 'POST';
unset($_SERVER['CONTENT_TYPE']);
$route = new Route('/sample', [
'controller' => 'posts',
'action' => 'index',
'_method' => 'POST',
'[type]' => 'application/xml'
]);
$this->assertFalse($route->parse('/sample'), 'No content type set.');

$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/json';
$this->assertFalse($route->parse('/sample'), 'Wrong content type set.');

$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$expected = [
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'_method' => 'POST',
'[type]' => 'application/xml',
];
$this->assertEquals($expected, $route->parse('/sample'));
}

/**
* Check [method] compatibility.
*
Expand Down

0 comments on commit b0e39c1

Please sign in to comment.