[TASK] Rename CodeCompletion to CodeCompletionController 12/56312/4
authorMathias Brodala <mbrodala@pagemachine.de>
Sat, 17 Mar 2018 14:36:21 +0000 (15:36 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Mar 2018 15:22:20 +0000 (16:22 +0100)
Change-Id: Ia913d08b832f27250a0def2cc1b6873210a1d8a6
Resolves: #84410
Releases: master
Reviewed-on: https://review.typo3.org/56312
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
composer.json
composer.lock
typo3/sysext/core/Documentation/Changelog/master/Deprecation-84410-CodeCompletionRenamedToCodeCompletionController.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
typo3/sysext/t3editor/Classes/CodeCompletion.php [deleted file]
typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php [new file with mode: 0644]
typo3/sysext/t3editor/Configuration/Backend/AjaxRoutes.php
typo3/sysext/t3editor/Migrations/Code/ClassAliasMap.php [new file with mode: 0644]
typo3/sysext/t3editor/Migrations/Code/LegacyClassesForIde.php [new file with mode: 0644]
typo3/sysext/t3editor/composer.json

index a0c1004..bb55b82 100644 (file)
@@ -89,6 +89,7 @@
                                "typo3/sysext/recordlist/Migrations/Code/ClassAliasMap.php",
                                "typo3/sysext/reports/Migrations/Code/ClassAliasMap.php",
                                "typo3/sysext/saltedpasswords/Migrations/Code/ClassAliasMap.php",
+                               "typo3/sysext/t3editor/Migrations/Code/ClassAliasMap.php",
                                "typo3/sysext/workspaces/Migrations/Code/ClassAliasMap.php"
                        ]
                },
index 898274f..bced5a1 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "33161a8bc06421b8de725e3dfb422fae",
+    "content-hash": "9e7e4b2f0374c71e482a335873a428aa",
     "packages": [
         {
             "name": "cogpowered/finediff",
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84410-CodeCompletionRenamedToCodeCompletionController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84410-CodeCompletionRenamedToCodeCompletionController.rst
new file mode 100644 (file)
index 0000000..2644cd0
--- /dev/null
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+========================================================================
+Deprecation: #84410 - CodeCompletion renamed to CodeCompletionController
+========================================================================
+
+See :issue:`84410`
+
+Description
+===========
+
+The PHP class :php:`TYPO3\CMS\T3editor\CodeCompletion` has been renamed to
+:php:`TYPO3\CMS\T3editor\Controller\CodeCompletionController`.
+
+
+Impact
+======
+
+The old class name has been registered as class alias and will still work.
+Old class name usage however is discouraged and should be avoided since, the
+alias will vanish with core version 10.
+
+
+Affected Installations
+======================
+
+Extensions which use the old class name are affected. The extension scanner will find affected extensions using the old class name.
+
+
+Migration
+=========
+
+Use new class name instead.
+
+.. index:: Backend, PHP-API, FullyScanned, ext:t3editor
\ No newline at end of file
index 5ac17f7..a2f024d 100644 (file)
@@ -659,4 +659,9 @@ return [
             'Deprecation-84399-ClassRecordListRenamedToRecordListController.rst',
         ],
     ],
+    'TYPO3\CMS\T3editor\CodeCompletion' => [
+        'restFiles' => [
+            'Deprecation-84410-CodeCompletionRenamedToCodeCompletionController.rst',
+        ],
+    ],
 ];
diff --git a/typo3/sysext/t3editor/Classes/CodeCompletion.php b/typo3/sysext/t3editor/Classes/CodeCompletion.php
deleted file mode 100644 (file)
index 5770cb2..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-namespace TYPO3\CMS\T3editor;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
-use TYPO3\CMS\Core\Http\JsonResponse;
-
-/**
- * Code completion for t3editor
- */
-class CodeCompletion
-{
-    /**
-     * @var \TYPO3\CMS\Core\Http\AjaxRequestHandler
-     */
-    protected $ajaxObj;
-
-    /**
-     * Default constructor
-     */
-    public function __construct()
-    {
-        $GLOBALS['LANG']->includeLLFile('EXT:t3editor/Resources/Private/Language/locallang.xlf');
-    }
-
-    /**
-     * General processor for AJAX requests.
-     * Called by AjaxRequestHandler
-     *
-     * @param ServerRequestInterface $request
-     * @return ResponseInterface
-     */
-    public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface
-    {
-        $pageId = (int)($request->getParsedBody()['pageId'] ?? $request->getQueryParams()['pageId']);
-        return $this->loadTemplates($pageId);
-    }
-
-    /**
-     * Loads all templates up to a given page id (walking the rootline) and
-     * cleans parts that are not required for the t3editor codecompletion.
-     *
-     * @param int $pageId ID of the page
-     * @return ResponseInterface
-     */
-    protected function loadTemplates($pageId): ResponseInterface
-    {
-        // Check whether access is granted (only admin have access to sys_template records):
-        if ($GLOBALS['BE_USER']->isAdmin()) {
-            // Check whether there is a pageId given:
-            if ($pageId) {
-                return (new JsonResponse())->setPayload($this->getMergedTemplates($pageId));
-            }
-            return new HtmlResponse($GLOBALS['LANG']->getLL('pageIDInteger'), 500);
-        }
-        return new HtmlResponse($GLOBALS['LANG']->getLL('noPermission'), 500);
-    }
-
-    /**
-     * Gets merged templates by walking the rootline to a given page id.
-     *
-     * @todo oliver@typo3.org: Refactor this method and comment what's going on there
-     * @param int $pageId
-     * @return array Setup part of merged template records
-     */
-    protected function getMergedTemplates($pageId)
-    {
-        /** @var $tsParser \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
-        $tsParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
-        $tsParser->init();
-        // Gets the rootLine
-        $page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
-        $rootLine = $page->getRootLine($pageId);
-        // This generates the constants/config + hierarchy info for the template.
-        $tsParser->runThroughTemplates($rootLine);
-        // ts-setup & ts-constants of the currently edited template should not be included
-        // therefor we have to delete the last template from the stack
-        array_pop($tsParser->config);
-        array_pop($tsParser->constants);
-        $tsParser->linkObjects = true;
-        $tsParser->ext_regLinenumbers = false;
-        $tsParser->generateConfig();
-        $result = $this->treeWalkCleanup($tsParser->setup);
-        return $result;
-    }
-
-    /**
-     * Walks through a tree of TypoScript configuration an cleans it up.
-     *
-     * @TODO oliver@typo3.org: Define and comment why this is necessary and exactly happens below
-     * @param array $treeBranch TypoScript configuration or sub branch of it
-     * @return array Cleaned TypoScript branch
-     */
-    private function treeWalkCleanup(array $treeBranch)
-    {
-        $cleanedTreeBranch = [];
-        foreach ($treeBranch as $key => $value) {
-            $dotCount = substr_count($key, '.');
-            //type definition or value-assignment
-            if ($dotCount == 0) {
-                if ($value != '') {
-                    if (strlen($value) > 20) {
-                        $value = substr($value, 0, 20);
-                    }
-                    if (!isset($cleanedTreeBranch[$key])) {
-                        $cleanedTreeBranch[$key] = [];
-                    }
-                    $cleanedTreeBranch[$key]['v'] = $value;
-                }
-            } elseif ($dotCount == 1) {
-                // subtree (definition of properties)
-                $subBranch = $this->treeWalkCleanup($value);
-                if ($subBranch) {
-                    $key = str_replace('.', '', $key);
-                    if (!isset($cleanedTreeBranch[$key])) {
-                        $cleanedTreeBranch[$key] = [];
-                    }
-                    $cleanedTreeBranch[$key]['c'] = $subBranch;
-                }
-            }
-        }
-        return $cleanedTreeBranch;
-    }
-}
diff --git a/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php b/typo3/sysext/t3editor/Classes/Controller/CodeCompletionController.php
new file mode 100644 (file)
index 0000000..a9e9980
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+namespace TYPO3\CMS\T3editor\Controller;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\JsonResponse;
+
+/**
+ * Code completion for t3editor
+ */
+class CodeCompletionController
+{
+    /**
+     * @var \TYPO3\CMS\Core\Http\AjaxRequestHandler
+     */
+    protected $ajaxObj;
+
+    /**
+     * Default constructor
+     */
+    public function __construct()
+    {
+        $GLOBALS['LANG']->includeLLFile('EXT:t3editor/Resources/Private/Language/locallang.xlf');
+    }
+
+    /**
+     * General processor for AJAX requests.
+     * Called by AjaxRequestHandler
+     *
+     * @param ServerRequestInterface $request
+     * @return ResponseInterface
+     */
+    public function loadCompletions(ServerRequestInterface $request): ResponseInterface
+    {
+        $pageId = (int)($request->getParsedBody()['pageId'] ?? $request->getQueryParams()['pageId']);
+        return $this->loadTemplates($pageId);
+    }
+
+    /**
+     * Loads all templates up to a given page id (walking the rootline) and
+     * cleans parts that are not required for the t3editor codecompletion.
+     *
+     * @param int $pageId ID of the page
+     * @return ResponseInterface
+     */
+    protected function loadTemplates($pageId): ResponseInterface
+    {
+        // Check whether access is granted (only admin have access to sys_template records):
+        if ($GLOBALS['BE_USER']->isAdmin()) {
+            // Check whether there is a pageId given:
+            if ($pageId) {
+                return (new JsonResponse())->setPayload($this->getMergedTemplates($pageId));
+            }
+            return new HtmlResponse($GLOBALS['LANG']->getLL('pageIDInteger'), 500);
+        }
+        return new HtmlResponse($GLOBALS['LANG']->getLL('noPermission'), 500);
+    }
+
+    /**
+     * Gets merged templates by walking the rootline to a given page id.
+     *
+     * @todo oliver@typo3.org: Refactor this method and comment what's going on there
+     * @param int $pageId
+     * @return array Setup part of merged template records
+     */
+    protected function getMergedTemplates($pageId)
+    {
+        /** @var $tsParser \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
+        $tsParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
+        $tsParser->init();
+        // Gets the rootLine
+        $page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+        $rootLine = $page->getRootLine($pageId);
+        // This generates the constants/config + hierarchy info for the template.
+        $tsParser->runThroughTemplates($rootLine);
+        // ts-setup & ts-constants of the currently edited template should not be included
+        // therefor we have to delete the last template from the stack
+        array_pop($tsParser->config);
+        array_pop($tsParser->constants);
+        $tsParser->linkObjects = true;
+        $tsParser->ext_regLinenumbers = false;
+        $tsParser->generateConfig();
+        $result = $this->treeWalkCleanup($tsParser->setup);
+        return $result;
+    }
+
+    /**
+     * Walks through a tree of TypoScript configuration an cleans it up.
+     *
+     * @TODO oliver@typo3.org: Define and comment why this is necessary and exactly happens below
+     * @param array $treeBranch TypoScript configuration or sub branch of it
+     * @return array Cleaned TypoScript branch
+     */
+    private function treeWalkCleanup(array $treeBranch)
+    {
+        $cleanedTreeBranch = [];
+        foreach ($treeBranch as $key => $value) {
+            $dotCount = substr_count($key, '.');
+            //type definition or value-assignment
+            if ($dotCount == 0) {
+                if ($value != '') {
+                    if (strlen($value) > 20) {
+                        $value = substr($value, 0, 20);
+                    }
+                    if (!isset($cleanedTreeBranch[$key])) {
+                        $cleanedTreeBranch[$key] = [];
+                    }
+                    $cleanedTreeBranch[$key]['v'] = $value;
+                }
+            } elseif ($dotCount == 1) {
+                // subtree (definition of properties)
+                $subBranch = $this->treeWalkCleanup($value);
+                if ($subBranch) {
+                    $key = str_replace('.', '', $key);
+                    if (!isset($cleanedTreeBranch[$key])) {
+                        $cleanedTreeBranch[$key] = [];
+                    }
+                    $cleanedTreeBranch[$key]['c'] = $subBranch;
+                }
+            }
+        }
+        return $cleanedTreeBranch;
+    }
+}
index 8af7cb2..7a0f00c 100644 (file)
@@ -13,6 +13,6 @@ return [
     // Load code completion templates
     't3editor_codecompletion_loadtemplates' => [
         'path' => '/t3editor/codecompletion/load-templates',
-        'target' => \TYPO3\CMS\T3editor\CodeCompletion::class . '::processAjaxRequest'
+        'target' => \TYPO3\CMS\T3editor\Controller\CodeCompletionController::class . '::loadCompletions'
     ]
 ];
diff --git a/typo3/sysext/t3editor/Migrations/Code/ClassAliasMap.php b/typo3/sysext/t3editor/Migrations/Code/ClassAliasMap.php
new file mode 100644 (file)
index 0000000..d8e5c23
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+return [
+    'TYPO3\\CMS\\T3editor\\CodeCompletion' => \TYPO3\CMS\T3editor\Controller\CodeCompletionController::class,
+];
diff --git a/typo3/sysext/t3editor/Migrations/Code/LegacyClassesForIde.php b/typo3/sysext/t3editor/Migrations/Code/LegacyClassesForIde.php
new file mode 100644 (file)
index 0000000..44cfd02
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+namespace {
+    die('Access denied');
+}
+
+namespace TYPO3\CMS\T3editor {
+    /**
+     * @deprecated since v9, will be removed in v10
+     */
+    class CodeCompletion extends \TYPO3\CMS\T3editor\Controller\CodeCompletionController
+    {
+    }
+}
index 7f2a88b..6610a3e 100644 (file)
                                "partOfFactoryDefault": true
                        },
                        "extension-key": "t3editor"
+               },
+               "typo3/class-alias-loader": {
+                       "class-alias-maps": [
+                               "Migrations/Code/ClassAliasMap.php"
+                       ]
                }
        },
        "autoload": {