ソースを参照

Fix silencing errors in extension handling.

mscherer 7 年 前
コミット
fb720c7e60

+ 8 - 1
src/Controller/Component/RequestHandlerComponent.php

@@ -21,6 +21,7 @@ use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Exception\Exception;
 use Cake\Event\Event;
+use Cake\Http\Exception\NotFoundException;
 use Cake\Http\Response;
 use Cake\Routing\Router;
 use Cake\Utility\Exception\XmlException;
@@ -332,8 +333,11 @@ class RequestHandlerComponent extends Component
             !in_array($this->ext, ['html', 'htm']) &&
             $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);
             $response = $controller->response;
         } else {
@@ -594,6 +598,9 @@ class RequestHandlerComponent extends Component
         $viewClass = null;
         if ($builder->getClassName() === null) {
             $viewClass = App::className($view, 'View', 'View');
+            if ($viewClass === false) {
+                throw new RuntimeException('Configured view class can not be found: ' . $view);
+            }
         }
 
         if ($viewClass) {

+ 17 - 1
src/Http/Response.php

@@ -1111,7 +1111,7 @@ class Response implements ResponseInterface
     {
         deprecationWarning(
             'Response::type() is deprecated. ' .
-            'Use getType() or withType() instead.'
+            'Use getType(), setType() or withType() instead.'
         );
 
         if ($contentType === null) {
@@ -1138,6 +1138,22 @@ class Response implements ResponseInterface
     }
 
     /**
+     * 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.
      *
      * @return string