Deprecation: AccessRegistry methods
Description
Following
\Web methods
has been deprecated:
addbecause access items are gathered based on theAccess () \Accessand added through the constructor by the DI container. Calling this method does not add anything and emits now aItem Interface E_error.USER_ DEPRECATED getis now deprecated and triggers aAll Access () E_error. UseUSER_ DEPRECATED getinstead.Items () getis now deprecated and triggers aAccess () E_error. UseUSER_ DEPRECATED getinstead.() hasis now deprecated and triggers aAccess () E_error. UseUSER_ DEPRECATED hasinstead.()
Impact
Calling deprecated
\Web
methods triggers a
E_ error.
Affected installations
All installations that call one of the deprecated
\Web methods triggers a
E_ error. Use the above mentioned replacements or remove
the add calls in ext_.
Migration
addAccess()
To register additional
\Access
the approach have been to provide following code in EXT::
<?php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\Deepltranslate\Core\Access\AccessRegistry;
$accessRegistry = GeneralUtility::makeInstance(AccessRegistry::class);
$accessRegistry->addAccess(new CustomAccessItem());
This is no longer required and does not do anything except triggering an
E_ error and can be simply removed.
In case dual extension version support is required encapsulate it into a condition, for example:
<?php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\Deepltranslate\Core\Access\AccessRegistry;
use WebVision\Deepltranslate\Core\TranslatorInterface;
// @todo web-vision/deepltranslate-core:>=6.0.0 Remove complete condition
// block once lowest supported deepltranslate-core extension version
// has been raised to 6.0.0 or higher.
if (class_exists(TranslatorInterface::class) === false) {
$accessRegistry = GeneralUtility::makeInstance(AccessRegistry::class);
$accessRegistry->addAccess(new CustomAccessItem());
}
getAllAccess()
get can be replaced simply using the new get method:
<?php
namespace MyVendor\MyExt;
final class SomeClass {
public function __construct(
private AccessRegistry $accessRegistry,
) {}
public function someMethod(): void
{
- $allRegisteredAccessItems = $this->accessRegistry->getAllAccess();
+ // `getItems()` returns now the identifiers as keys and `array_values()`
+ // ensures to deal only with the items like with previous `getAllAccess()`.
+ $allRegisteredAccessItems = array_values($this->accessRegistry->getItems());
foreach($allRegisteredAccessItems as $accessItem) {
// ... do something with the access item
}
}
}
hasAccess(), getAccess()
Deprecated
has and get can be simply replaced by their
new counter methods based on the now used
\Psr\:
<?php
namespace MyVendor\MyExt;
final class SomeClass {
public function __construct(
private AccessRegistry $accessRegistry,
) {}
public function hasAccess(): bool
{
$accessIdentifier = '';
- if (!$this->accessRegistry->hasAccess($accessIdentifier)) {
+ if (!$this->accessRegistry->has($accessIdentifier)) {
// access does not exists, take this as allowed.
return true;
}
- $accessItem = $this->accessRegistry->getAccess($accessIdentifier);
+ $accessItem = $this->accessRegistry->get($accessIdentifier);
return $this->getBackendUserAuthentication()->check(
'custom_options',
sprintf('deepltranslate:%s', $accessItem->getIdentifier()),
);
}
private function getBackendUserAuthentication(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}