Skip to content
Permalink
Browse files

Remove the header matching from Route::parse()

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 b0e39c1ab6c2bde6169fe51358a3aedaad10688b
Showing with 0 additions and 65 deletions.
  1. +0 −33 src/Routing/Route/Route.php
  2. +0 −32 tests/TestCase/Routing/Route/RouteTest.php
@@ -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.
*
@@ -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++) {
@@ -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.
*

0 comments on commit b0e39c1

Please sign in to comment.
You can’t perform that action at this time.