[!!!][TASK] Remove view related properties from ActionController 14/59514/6
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 21 Jan 2019 16:13:05 +0000 (17:13 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 31 Jan 2019 06:22:50 +0000 (07:22 +0100)
Both properties $namespacesViewObjectNamePattern and
$viewFormatToObjectNameMap of class ActionController
have been removed without replacement.

Both properties provided a functionality to set a
custom view object class during runtime. As this
contradicts the idea of having a defined state per
request by configuring concrete implementations
before runtime, these properties needed to vanish.

While there is no dependency injection with a proper
configuration available, the view object class can
still be defined via property $defaultViewObjectName.

Releases: master
Resolves: #87511
Change-Id: I4b89a9434f71a3cbf38a9ad113ba8233e7f327f9
Reviewed-on: https://review.typo3.org/59514
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Achim Fritz <af@achimfritz.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveNamespacesViewObjectNamePatternProperty.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveViewFormatToObjectNameMapProperty.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ActionControllerTest.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveNamespacesViewObjectNamePatternProperty.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveNamespacesViewObjectNamePatternProperty.rst
new file mode 100644 (file)
index 0000000..bc8338e
--- /dev/null
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+===================================================================
+Breaking: #87511 - Remove $namespacesViewObjectNamePattern property
+===================================================================
+
+See :issue:`87511`
+
+Description
+===========
+
+Property :php:`$namespacesViewObjectNamePattern` of class
+:php:`\TYPO3\CMS\Extbase\Mvc\Controller\ActionController` has been
+removed without replacement.
+
+Impact
+======
+
+Overriding the property :php:`$namespacesViewObjectNamePattern` in
+controllers that extend :php`ActionController` will no longer trigger
+the instantiation of another view object, derived from the pattern.
+
+Affected Installations
+======================
+
+All extensions that override the property :php:`$namespacesViewObjectNamePattern`.
+
+Migration
+=========
+
+If an action needs another template object other than the default
+:php:`\TYPO3\CMS\Fluid\View\TemplateView`, the property :php:`$defaultViewObjectName`
+needs to be overridden instead.
+
+.. index:: PHP-API, FullyScanned, ext:extbase
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveViewFormatToObjectNameMapProperty.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-87511-RemoveViewFormatToObjectNameMapProperty.rst
new file mode 100644 (file)
index 0000000..7a06d88
--- /dev/null
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+=============================================================
+Breaking: #87511 - Remove $viewFormatToObjectNameMap property
+=============================================================
+
+See :issue:`87511`
+
+Description
+===========
+
+Property :php:`$viewFormatToObjectNameMap` of class
+:php:`\TYPO3\CMS\Extbase\Mvc\Controller\ActionController` has been
+removed without replacement.
+
+Impact
+======
+
+Overriding the property :php:`$viewFormatToObjectNameMap` in
+controllers that extend :php`ActionController` will no longer trigger
+the instantiation of another view object, derived from the mapping.
+
+Affected Installations
+======================
+
+All extensions that override the property :php:`$viewFormatToObjectNameMap`.
+
+Migration
+=========
+
+If an action needs another template object other than the default
+:php:`\TYPO3\CMS\Fluid\View\TemplateView`, the property :php:`$defaultViewObjectName`
+needs to be overridden instead.
+
+.. index:: PHP-API, FullyScanned, ext:extbase
index af22e4e..e4c1cde 100644 (file)
@@ -47,22 +47,6 @@ class ActionController extends AbstractController
     protected $view;
 
     /**
-     * @var string
-     */
-    protected $namespacesViewObjectNamePattern = '@vendor\@extension\View\@controller\@action@format';
-
-    /**
-     * A list of formats and object names of the views which should render them.
-     *
-     * Example:
-     *
-     * array('html' => 'Tx_MyExtension_View_MyHtmlView', 'json' => 'F3...
-     *
-     * @var array
-     */
-    protected $viewFormatToObjectNameMap = [];
-
-    /**
      * The default view object to use if none of the resolved views can render
      * a response for the current request.
      *
@@ -347,16 +331,7 @@ class ActionController extends AbstractController
      */
     protected function resolveView()
     {
-        $viewObjectName = $this->resolveViewObjectName();
-        if ($viewObjectName !== false) {
-            /** @var ViewInterface $view */
-            $view = $this->objectManager->get($viewObjectName);
-            $this->setViewConfiguration($view);
-            if ($view->canRender($this->controllerContext) === false) {
-                unset($view);
-            }
-        }
-        if (!isset($view) && $this->defaultViewObjectName != '') {
+        if ($this->defaultViewObjectName != '') {
             /** @var ViewInterface $view */
             $view = $this->objectManager->get($this->defaultViewObjectName);
             $this->setViewConfiguration($view);
@@ -448,44 +423,6 @@ class ActionController extends AbstractController
     }
 
     /**
-     * Determines the fully qualified view object name.
-     *
-     * @return mixed The fully qualified view object name or FALSE if no matching view could be found.
-     */
-    protected function resolveViewObjectName()
-    {
-        $vendorName = $this->request->getControllerVendorName();
-        if ($vendorName === null) {
-            return false;
-        }
-
-        $possibleViewName = str_replace(
-            [
-                '@vendor',
-                '@extension',
-                '@controller',
-                '@action'
-            ],
-            [
-                $vendorName,
-                $this->request->getControllerExtensionName(),
-                $this->request->getControllerName(),
-                ucfirst($this->request->getControllerActionName())
-            ],
-            $this->namespacesViewObjectNamePattern
-        );
-        $format = $this->request->getFormat();
-        $viewObjectName = str_replace('@format', ucfirst($format), $possibleViewName);
-        if (class_exists($viewObjectName) === false) {
-            $viewObjectName = str_replace('@format', '', $possibleViewName);
-        }
-        if (isset($this->viewFormatToObjectNameMap[$format]) && class_exists($viewObjectName) === false) {
-            $viewObjectName = $this->viewFormatToObjectNameMap[$format];
-        }
-        return class_exists($viewObjectName) ? $viewObjectName : false;
-    }
-
-    /**
      * Initializes the view before invoking an action method.
      *
      * Override this method to solve assign variables common for all actions
index 320281e..2e515d9 100644 (file)
@@ -19,17 +19,14 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
-use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
 use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException;
 use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException;
 use TYPO3\CMS\Extbase\Mvc\Request;
 use TYPO3\CMS\Extbase\Mvc\RequestInterface;
 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
-use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Reflection\ClassSchema;
 use TYPO3\CMS\Extbase\Reflection\ReflectionService;
-use TYPO3\CMS\Fluid\View\TemplateView;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 use TYPO3Fluid\Fluid\View\AbstractTemplateView;
 use TYPO3Fluid\Fluid\View\TemplateView as FluidTemplateView;
@@ -67,67 +64,6 @@ class ActionControllerTest extends UnitTestCase
     /**
      * @test
      */
-    public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable()
-    {
-        $mockControllerContext = $this->createMock(ControllerContext::class);
-        $mockFluidTemplateView = $this->createMock(ViewInterface::class);
-        $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
-        $mockFluidTemplateView->expects($this->once())->method('canRender')->with($mockControllerContext)->will($this->returnValue(true));
-        $mockObjectManager = $this->createMock(ObjectManagerInterface::class);
-        $mockObjectManager->expects($this->at(0))->method('get')->with(TemplateView::class)->will($this->returnValue($mockFluidTemplateView));
-        $mockController = $this->getAccessibleMock(ActionController::class, ['buildControllerContext', 'resolveViewObjectName', 'setViewConfiguration'], [], '', false);
-        $mockController->expects($this->once())->method('resolveViewObjectName')->will($this->returnValue(false));
-        $mockController->_set('objectManager', $mockObjectManager);
-        $mockController->_set('controllerContext', $mockControllerContext);
-        $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
-    }
-
-    /**
-     * @test
-     */
-    public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName()
-    {
-        $mockRequest = $this->createMock(Request::class);
-        $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
-        $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
-        $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
-        $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
-        $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
-        $mockObjectManager = $this->createMock(ObjectManagerInterface::class);
-        $mockController = $this->getAccessibleMock(ActionController::class, ['dummy'], [], '', false);
-        $mockController->_set('request', $mockRequest);
-        $mockController->_set('objectManager', $mockObjectManager);
-        $mockController->_set('namespacesViewObjectNamePattern', 'RandomViewObject@vendor\@extension\View\@controller\@action@format');
-        $mockController->_call('resolveViewObjectName');
-    }
-
-    /**
-     * @test
-     */
-    public function resolveViewObjectNameUsesNamespacedViewObjectNamePatternForExtensionsWithVendor()
-    {
-        eval('namespace MyVendor\MyPackage\View\MyController; class MyActionMyFormat {}');
-
-        $mockRequest = $this->createMock(Request::class);
-        $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
-        $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
-        $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
-        $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
-        $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
-        $mockObjectManager = $this->createMock(ObjectManagerInterface::class);
-        $mockController = $this->getAccessibleMock(ActionController::class, ['dummy'], [], '', false);
-        $mockController->_set('request', $mockRequest);
-        $mockController->_set('objectManager', $mockObjectManager);
-
-        $this->assertEquals(
-            'MyVendor\MyPackage\View\MyController\MyActionMyFormat',
-            $mockController->_call('resolveViewObjectName')
-        );
-    }
-
-    /**
-     * @test
-     */
     public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest()
     {
         $mockRequest = $this->createMock(Request::class);
index 418d4a9..7d277b5 100644 (file)
@@ -1243,4 +1243,14 @@ return [
             'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
+    'TYPO3\CMS\Extbase\Mvc\Controller\ActionController->namespacesViewObjectNamePattern' => [
+        'restFiles' => [
+            'Breaking-87511-RemoveNamespacesViewObjectNamePatternProperty.rst',
+        ],
+    ],
+    'TYPO3\CMS\Extbase\Mvc\Controller\ActionController->viewFormatToObjectNameMap' => [
+        'restFiles' => [
+            'Breaking-87511-RemoveViewFormatToObjectNameMapProperty.rst',
+        ],
+    ],
 ];
index 1dd7183..44c2e31 100644 (file)
@@ -519,4 +519,14 @@ return [
             'Breaking-87193-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
+    'TYPO3\CMS\Extbase\Mvc\Controller\ActionController->namespacesViewObjectNamePattern' => [
+        'restFiles' => [
+            'Breaking-87511-RemoveNamespacesViewObjectNamePatternProperty.rst',
+        ],
+    ],
+    'TYPO3\CMS\Extbase\Mvc\Controller\ActionController->viewFormatToObjectNameMap' => [
+        'restFiles' => [
+            'Breaking-87511-RemoveViewFormatToObjectNameMapProperty.rst',
+        ],
+    ],
 ];