Skip to content
Permalink
Browse files

Move logic of whether to include 'method' to MissingRouteException co…

…nstructor
  • Loading branch information...
mikeu committed Jan 8, 2017
1 parent 2c3b50f commit e3bbf3829188a3c3a41c7e7662f6a6aec129656e
@@ -26,13 +26,24 @@ class MissingRouteException extends Exception
*/
protected $_messageTemplate = 'A route matching "%s" could not be found.';
/**
* Message template to use when the requested method is included.
*
* @var string
*/
protected $_messageTemplateWithMethod = 'A "%s" route matching "%s" could not be found.';
/**
* {@inheritDoc}
*/
public function __construct($message, $code = 404)
{
if (is_array($message) && isset($message['message'])) {
$this->_messageTemplate = $message['message'];
if (is_array($message)) {
if (isset($message['message'])) {
$this->_messageTemplate = $message['message'];
} elseif (isset($message['method']) && $message['method']) {
$this->_messageTemplate = $this->_messageTemplateWithMethod;
}
}
parent::__construct($message, $code);
}
@@ -144,11 +144,15 @@ public function parse($url, $method = '')
return $r;
}
}
throw new MissingRouteException([
'method' => $method,
'url' => $url,
'message' => 'A "%s" route matching "%s" could not be found.',
]);
$exceptionProperties = ['url' => $url];
if ($method !== '') {
// Ensure that if the method is included, it is the first element of
// the array, to match the order that the strings are printed in the
// MissingRouteException error message, $_messageTemplateWithMethod.
$exceptionProperties = array_merge(['method' => $method], $exceptionProperties);
}
throw new MissingRouteException($exceptionProperties);
}
/**
@@ -37,7 +37,7 @@ public function setUp()
* Test parse() throws an error on unknown routes.
*
* @expectedException \Cake\Routing\Exception\MissingRouteException
* @expectedExceptionMessage A "" route matching "/" could not be found
* @expectedExceptionMessage A route matching "/" could not be found
*/
public function testParseMissingRoute()
{

0 comments on commit e3bbf38

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