Skip to content

Commit

Permalink
[TASK] Use trait for public method access deprecation
Browse files Browse the repository at this point in the history
Resolves: #85344
Releases: master
Change-Id: I47e42e974ea14f91b192c6521196c972c404b442
Reviewed-on: https://review.typo3.org/57300
Reviewed-by: Sebastian Hofer <sebastian.hofer@marit.ag>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Tested-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
  • Loading branch information
mbrodala authored and andreaswolf committed Jun 25, 2018
1 parent 99aea9d commit 4cb53e8
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 99 deletions.
Expand Up @@ -20,6 +20,7 @@
use TYPO3\CMS\Backend\Backend\Avatar\Avatar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\HtmlResponse;
Expand All @@ -38,14 +39,22 @@
*/
class ElementInformationController
{
use PublicMethodDeprecationTrait;
use PublicPropertyDeprecationTrait;

/**
* @var array
*/
private $deprecatedPublicMethods = [
'getLabelForTableColumn' => 'Using ElementInformationController::getLabelForTableColumn() is deprecated and will not be possible anymore in TYPO3 v10.',
];

/**
* Properties which have been moved to protected status from public
*
* @var array
*/
protected $deprecatedPublicProperties = [
private $deprecatedPublicProperties = [
'table' => 'Using $table of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
'uid' => 'Using $uid of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
'access' => 'Using $access of class ElementInformationController from the outside is discouraged, as this variable is only used for internal storage.',
Expand Down Expand Up @@ -497,15 +506,8 @@ protected function getReferences(ServerRequestInterface $request): array
* @param string $fieldName Column name
* @return string label
*/
public function getLabelForTableColumn($tableName, $fieldName)
protected function getLabelForTableColumn($tableName, $fieldName)
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method getLabelForTableColumn() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label'] !== null) {
$field = $this->getLanguageService()->sL($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['label']);
if (trim($field) === '') {
Expand Down
70 changes: 21 additions & 49 deletions typo3/sysext/backend/Classes/Controller/EditDocumentController.php
Expand Up @@ -28,6 +28,7 @@
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
Expand Down Expand Up @@ -60,6 +61,7 @@
*/
class EditDocumentController
{
use PublicMethodDeprecationTrait;
use PublicPropertyDeprecationTrait;

/**
Expand All @@ -70,12 +72,24 @@ class EditDocumentController
public const DOCUMENT_CLOSE_MODE_CLEAR_ALL = 3;
public const DOCUMENT_CLOSE_MODE_NO_REDIRECT = 4;

/**
* @var array
*/
private $deprecatedPublicMethods = [
'makeEditForm' => 'Using EditDocumentController::makeEditForm() is deprecated and will not be possible anymore in TYPO3 v10.',
'compileForm' => 'Using EditDocumentController::compileForm() is deprecated and will not be possible anymore in TYPO3 v10.',
'languageSwitch' => 'Using EditDocumentController::languageSwitch() is deprecated and will not be possible anymore in TYPO3 v10.',
'getLanguages' => 'Using EditDocumentController::getLanguages() is deprecated and will not be possible anymore in TYPO3 v10.',
'fixWSversioningInEditConf' => 'Using EditDocumentController::fixWSversioningInEditConf() is deprecated and will not be possible anymore in TYPO3 v10.',
'getRecordForEdit' => 'Using EditDocumentController::getRecordForEdit() is deprecated and will not be possible anymore in TYPO3 v10.',
];

/**
* Properties which have been moved to protected status from public
*
* @var array
*/
protected $deprecatedPublicProperties = [
private $deprecatedPublicProperties = [
'editconf' => 'Using $editconf of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'defVals' => 'Using $defVals of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'overrideVals' => 'Using $overrideVals of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
Expand Down Expand Up @@ -1207,15 +1221,8 @@ public function main(ServerRequestInterface $request = null): void
*
* @return string HTML form elements wrapped in tables
*/
public function makeEditForm(): string
protected function makeEditForm(): string
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method makeEditForm() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

// Initialize variables
$this->elementsData = [];
$this->errorC = 0;
Expand Down Expand Up @@ -2069,15 +2076,8 @@ protected function getQueryBuilderForTranslationMode(int $page, int $column, int
* @param string $editForm HTML form.
* @return string Composite HTML
*/
public function compileForm(string $editForm): string
protected function compileForm(string $editForm): string
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method compileForm() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

$formContent = '
<form
action="' . htmlspecialchars($this->R_URI) . '"
Expand Down Expand Up @@ -2205,15 +2205,8 @@ protected function getCloseUrl(): string
* @param int $uid Uid for which to create a new language
* @param int $pid|null Pid of the record
*/
public function languageSwitch(string $table, int $uid, $pid = null)
protected function languageSwitch(string $table, int $uid, $pid = null)
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method fixWSversioningInEditConf() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

$languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
$transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
/** @var UriBuilder $uriBuilder */
Expand Down Expand Up @@ -2436,15 +2429,8 @@ public function localizationRedirect(ServerRequestInterface $request = null): ?R
* @param string $table For pages we want all languages, for other records the languages of the page translations
* @return array Language records including faked record for default language
*/
public function getLanguages(int $id, string $table = ''): array
protected function getLanguages(int $id, string $table = ''): array
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method getLanguages() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

$languageService = $this->getLanguageService();
$modPageTsConfig = BackendUtility::getPagesTSconfig($id)['mod.']['SHARED.'] ?? [];
// Fallback non sprite-configuration
Expand Down Expand Up @@ -2524,15 +2510,8 @@ public function joinPagesTranslationsForActiveLanguage(QueryBuilder $queryBuilde
*
* @param array|bool $mapArray Mapping between old and new ids if auto-versioning has been performed.
*/
public function fixWSversioningInEditConf($mapArray = false): void
protected function fixWSversioningInEditConf($mapArray = false): void
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method fixWSversioningInEditConf() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

// Traverse the editConf array
if (is_array($this->editconf)) {
// Tables:
Expand Down Expand Up @@ -2578,15 +2557,8 @@ public function fixWSversioningInEditConf($mapArray = false): void
* @param int $theUid Record UID
* @return array|false Returns record to edit, false if none
*/
public function getRecordForEdit(string $table, int $theUid)
protected function getRecordForEdit(string $table, int $theUid)
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method getRecordForEdit() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

// Fetch requested record:
$reqRecord = BackendUtility::getRecord($table, $theUid, 'uid,pid');
if (is_array($reqRecord)) {
Expand Down
Expand Up @@ -20,6 +20,7 @@
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
Expand All @@ -38,12 +39,20 @@
*/
class CreateFolderController
{
use PublicMethodDeprecationTrait;
use PublicPropertyDeprecationTrait;

/**
* @var array
*/
protected $deprecatedPublicProperties = [
private $deprecatedPublicMethods = [
'main' => 'Using CreateFolderController::main() is deprecated and will not be possible anymore in TYPO3 v10.',
];

/**
* @var array
*/
private $deprecatedPublicProperties = [
'number' => 'Using $number of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'folderNumber' => 'Using $folderNumber of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
'target' => 'Using $target of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.',
Expand Down Expand Up @@ -212,15 +221,8 @@ function backToList() {
/**
* Main function, rendering the main module content
*/
public function main()
protected function main()
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method main() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}

$lang = $this->getLanguageService();
$assigns = [];
$assigns['target'] = $this->target;
Expand Down
44 changes: 26 additions & 18 deletions typo3/sysext/backend/Classes/Controller/File/EditFileController.php
Expand Up @@ -24,6 +24,7 @@
use TYPO3\CMS\Backend\Template\DocumentTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RedirectResponse;
Expand All @@ -42,12 +43,20 @@
*/
class EditFileController
{
use PublicMethodDeprecationTrait;
use PublicPropertyDeprecationTrait;

/**
* @var array
*/
protected $deprecatedPublicProperties = [
private $deprecatedPublicMethods = [
'main' => 'Using EditFileController::main() is deprecated and will not be possible anymore in TYPO3 v10.',
];

/**
* @var array
*/
private $deprecatedPublicProperties = [
'origTarget' => 'Using $origTarget of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
'target' => 'Using $target of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
'returnUrl' => 'Using $returnUrl of class EditFileController from outside is discouraged, as this variable is only used for internal storage.',
Expand Down Expand Up @@ -129,12 +138,25 @@ public function __construct()
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
if ($response = $this->main()) {
if ($response = $this->process()) {
return $response;
}

return new HtmlResponse($this->moduleTemplate->renderContent());
}

/**
* Main function, rendering the actual content of the editing page
*/
protected function main()
{
$response = $this->process();

if ($response instanceof RedirectResponse) {
HttpUtility::redirect($response->getHeaderLine('location'), $response->getStatusCode());
}
}

/**
* Initialize script class
*
Expand Down Expand Up @@ -191,18 +213,8 @@ protected function init(ServerRequestInterface $request): void
*
* @return ResponseInterface|null Possible redirect response
*/
public function main(): ?ResponseInterface
protected function process(): ?ResponseInterface
{
// @deprecated Variable can be removed in v10
$deprecatedCaller = false;
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method main() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
$deprecatedCaller = true;
}

$dataColumnDefinition = [
'label' => htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:file'))
. ' ' . htmlspecialchars($this->target),
Expand Down Expand Up @@ -295,11 +307,7 @@ public function main(): ?ResponseInterface
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
$defaultFlashMessageQueue->enqueue($flashMessage);

if ($deprecatedCaller === true) {
HttpUtility::redirect($this->returnUrl, HttpUtility::HTTP_STATUS_500);
} else {
return new RedirectResponse($this->returnUrl, HttpUtility::HTTP_STATUS_500);
}
return new RedirectResponse($this->returnUrl, HttpUtility::HTTP_STATUS_500);
}

// Rendering of the output via fluid
Expand Down
27 changes: 13 additions & 14 deletions typo3/sysext/backend/Classes/Controller/File/FileController.php
Expand Up @@ -21,6 +21,7 @@
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Http\RedirectResponse;
Expand All @@ -42,6 +43,16 @@
*/
class FileController
{
use PublicMethodDeprecationTrait;

/**
* @var array
*/
private $deprecatedPublicMethods = [
'initClipboard' => 'Using FileController::initClipboard() is deprecated and will not be possible anymore in TYPO3 v10.',
'main' => 'Using FileController::main() is deprecated and will not be possible anymore in TYPO3 v10.',
];

/**
* Array of file-operations.
*
Expand Down Expand Up @@ -221,14 +232,8 @@ protected function init(ServerRequestInterface $request): void
/**
* Initialize the Clipboard. This will fetch the data about files to paste/delete if such an action has been sent.
*/
public function initClipboard(): void
protected function initClipboard(): void
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method initClipboard() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}
if (is_array($this->CB)) {
$clipObj = GeneralUtility::makeInstance(Clipboard::class);
$clipObj->initializeClipboard();
Expand All @@ -247,14 +252,8 @@ public function initClipboard(): void
* Performing the file admin action:
* Initializes the objects, setting permissions, sending data to object.
*/
public function main(): void
protected function main(): void
{
// Foreign class call? Method will be protected in v10, giving core freedom to move stuff around
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
if (end($backtrace)['class'] !== __CLASS__) {
// @deprecated since TYPO3 v9, this method will be set to protected in v10
trigger_error('Method main() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
}
// Initializing:
$this->fileProcessor->setActionPermissions();
$this->fileProcessor->setExistingFilesConflictMode($this->overwriteExistingFiles);
Expand Down

0 comments on commit 4cb53e8

Please sign in to comment.