Skip to content

Commit

Permalink
Fix silencing errors in extension handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 23, 2018
1 parent 4feee54 commit fb720c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Controller/Component/RequestHandlerComponent.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Core\Exception\Exception; use Cake\Core\Exception\Exception;
use Cake\Event\Event; use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response; use Cake\Http\Response;
use Cake\Routing\Router; use Cake\Routing\Router;
use Cake\Utility\Exception\XmlException; use Cake\Utility\Exception\XmlException;
Expand Down Expand Up @@ -332,8 +333,11 @@ public function beforeRender(Event $event)
!in_array($this->ext, ['html', 'htm']) && !in_array($this->ext, ['html', 'htm']) &&
$response->getMimeType($this->ext) $response->getMimeType($this->ext)
); );
if ($this->ext && !$isRecognized) {
throw new NotFoundException('Invoked extension not recognized: ' . $this->ext);
}


if ($this->ext && $isRecognized) { if ($this->ext) {
$this->renderAs($controller, $this->ext); $this->renderAs($controller, $this->ext);
$response = $controller->response; $response = $controller->response;
} else { } else {
Expand Down Expand Up @@ -594,6 +598,9 @@ public function renderAs(Controller $controller, $type, array $options = [])
$viewClass = null; $viewClass = null;
if ($builder->getClassName() === null) { if ($builder->getClassName() === null) {
$viewClass = App::className($view, 'View', 'View'); $viewClass = App::className($view, 'View', 'View');
if ($viewClass === false) {
throw new RuntimeException('Configured view class can not be found: ' . $view);
}
} }


if ($viewClass) { if ($viewClass) {
Expand Down
18 changes: 17 additions & 1 deletion src/Http/Response.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ public function type($contentType = null)
{ {
deprecationWarning( deprecationWarning(
'Response::type() is deprecated. ' . 'Response::type() is deprecated. ' .
'Use getType() or withType() instead.' 'Use getType(), setType() or withType() instead.'
); );


if ($contentType === null) { if ($contentType === null) {
Expand All @@ -1137,6 +1137,22 @@ public function type($contentType = null)
return $contentType; return $contentType;
} }


/**
* Sets a content type into the map.
*
* E.g.: setType('xhtml' => ['application/xhtml+xml', 'application/xhtml', 'text/xhtml'])
*
* This is needed for RequestHandlerComponent and recognition of types.
*
* @param string $type
* @param string|array $definition
* @return void
*/
public function setType($type, $definition)
{
$this->_mimeTypes[$type] = $definition;
}

/** /**
* Returns the current content type. * Returns the current content type.
* *
Expand Down

0 comments on commit fb720c7

Please sign in to comment.