Revert "Issue #3443493 by smustgrave, Gábor Hojtsy, mikelutz: Remove deprecated code from lib/State and lib/Session"
This reverts commit d494e6673e
.
merge-requests/7806/head
parent
d494e6673e
commit
81a30d34ef
|
@ -2,12 +2,18 @@
|
|||
|
||||
namespace Drupal\Core\Session;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
/**
|
||||
* Checks permissions for an account.
|
||||
*/
|
||||
class PermissionChecker implements PermissionCheckerInterface {
|
||||
|
||||
public function __construct(protected AccessPolicyProcessorInterface $processor) {
|
||||
public function __construct(protected EntityTypeManagerInterface|AccessPolicyProcessorInterface $processor) {
|
||||
if ($this->processor instanceof EntityTypeManagerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $processor argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3402107', E_USER_DEPRECATED);
|
||||
$this->processor = \Drupal::service('access_policy_processor');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,21 +13,47 @@ use Drupal\Core\Site\Settings;
|
|||
*/
|
||||
class PermissionsHashGenerator implements PermissionsHashGeneratorInterface {
|
||||
|
||||
/**
|
||||
* The private key service.
|
||||
*
|
||||
* @var \Drupal\Core\PrivateKey
|
||||
*/
|
||||
protected $privateKey;
|
||||
|
||||
/**
|
||||
* The cache backend interface to use for the static cache.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
*/
|
||||
protected $static;
|
||||
|
||||
/**
|
||||
* The access policy processor.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccessPolicyProcessorInterface
|
||||
*/
|
||||
protected $processor;
|
||||
|
||||
/**
|
||||
* Constructs a PermissionsHashGenerator object.
|
||||
*
|
||||
* @param \Drupal\Core\PrivateKey $privateKey
|
||||
* @param \Drupal\Core\PrivateKey $private_key
|
||||
* The private key service.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $static
|
||||
* The cache backend interface to use for the static cache.
|
||||
* @param \Drupal\Core\Session\AccessPolicyProcessorInterface $processor
|
||||
* @param \Drupal\Core\Session\AccessPolicyProcessorInterface|\Drupal\Core\Cache\CacheBackendInterface $processor
|
||||
* The access policy processor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected PrivateKey $privateKey,
|
||||
protected CacheBackendInterface $static,
|
||||
protected AccessPolicyProcessorInterface $processor,
|
||||
) {
|
||||
public function __construct(PrivateKey $private_key, CacheBackendInterface $static, AccessPolicyProcessorInterface|CacheBackendInterface $processor) {
|
||||
$this->privateKey = $private_key;
|
||||
if ($processor instanceof CacheBackendInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $processor argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3402110', E_USER_DEPRECATED);
|
||||
$this->static = $processor;
|
||||
$this->processor = \Drupal::service('access_policy_processor');
|
||||
return;
|
||||
}
|
||||
$this->static = $static;
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,6 +100,25 @@ class PermissionsHashGenerator implements PermissionsHashGeneratorInterface {
|
|||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a hash that uniquely identifies the user's permissions.
|
||||
*
|
||||
* @param string[] $roles
|
||||
* The user's roles.
|
||||
*
|
||||
* @return string
|
||||
* The permissions hash.
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
|
||||
* replacement.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3435842
|
||||
*/
|
||||
protected function doGenerate(array $roles) {
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3435842', E_USER_DEPRECATED);
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -17,21 +17,37 @@ class SessionHandler extends AbstractProxy implements \SessionHandlerInterface {
|
|||
|
||||
use DependencySerializationTrait;
|
||||
|
||||
/**
|
||||
* The request stack.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new SessionHandler instance.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
|
||||
* The request stack.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(
|
||||
protected RequestStack $requestStack,
|
||||
protected Connection $connection,
|
||||
protected TimeInterface $time,
|
||||
) {
|
||||
public function __construct(RequestStack $request_stack, Connection $connection, protected ?TimeInterface $time = NULL) {
|
||||
$this->requestStack = $request_stack;
|
||||
$this->connection = $connection;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Database\Connection;
|
|||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
|
||||
/**
|
||||
* Manages user sessions.
|
||||
|
@ -29,6 +30,27 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
|||
|
||||
use DependencySerializationTrait;
|
||||
|
||||
/**
|
||||
* The request stack.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* The database connection to use.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The session configuration.
|
||||
*
|
||||
* @var \Drupal\Core\Session\SessionConfigurationInterface
|
||||
*/
|
||||
protected $sessionConfiguration;
|
||||
|
||||
/**
|
||||
* Whether a lazy session has been started.
|
||||
*
|
||||
|
@ -49,15 +71,15 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
|||
/**
|
||||
* Constructs a new session manager instance.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
|
||||
* The request stack.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
* @param \Drupal\Core\Session\MetadataBag $metadata_bag
|
||||
* The session metadata bag.
|
||||
* @param \Drupal\Core\Session\SessionConfigurationInterface $sessionConfiguration
|
||||
* @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
|
||||
* The session configuration interface.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null|\Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy|\SessionHandlerInterface $time
|
||||
* The time service.
|
||||
* @param \Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy|\SessionHandlerInterface|null $handler
|
||||
* The object to register as a PHP session handler.
|
||||
|
@ -65,14 +87,26 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
|||
* @see \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()
|
||||
*/
|
||||
public function __construct(
|
||||
protected RequestStack $requestStack,
|
||||
protected Connection $connection,
|
||||
protected MetadataBag $metadata_bag,
|
||||
protected SessionConfigurationInterface $sessionConfiguration,
|
||||
protected TimeInterface $time,
|
||||
RequestStack $request_stack,
|
||||
Connection $connection,
|
||||
MetadataBag $metadata_bag,
|
||||
SessionConfigurationInterface $session_configuration,
|
||||
protected TimeInterface|AbstractProxy|\SessionHandlerInterface|null $time = NULL,
|
||||
$handler = NULL,
|
||||
) {
|
||||
parent::__construct([], $handler, $metadata_bag);
|
||||
$options = [];
|
||||
$this->sessionConfiguration = $session_configuration;
|
||||
$this->requestStack = $request_stack;
|
||||
$this->connection = $connection;
|
||||
if (!$time || $time instanceof AbstractProxy || $time instanceof \SessionHandlerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 5th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
if ($time instanceof AbstractProxy || $time instanceof \SessionHandlerInterface) {
|
||||
$handler = $time;
|
||||
}
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
|
||||
parent::__construct($options, $handler, $metadata_bag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -119,7 +119,11 @@ class UserSession implements AccountInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasPermission(string $permission) {
|
||||
public function hasPermission(/* string */$permission) {
|
||||
if (!is_string($permission)) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with a $permission parameter of type other than string is deprecated in drupal:10.3.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3411485', E_USER_DEPRECATED);
|
||||
return FALSE;
|
||||
}
|
||||
return \Drupal::service('permission_checker')->hasPermission($permission, $this);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\State;
|
||||
|
||||
use Drupal\Core\Asset\AssetQueryString;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\CacheCollector;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
|
@ -12,6 +13,22 @@ use Drupal\Core\Lock\LockBackendInterface;
|
|||
*/
|
||||
class State extends CacheCollector implements StateInterface {
|
||||
|
||||
/**
|
||||
* Information about all deprecated state, keyed by legacy state key.
|
||||
*
|
||||
* Each entry should be an array that defines the following keys:
|
||||
* - 'replacement': The new name for the state.
|
||||
* - 'message': The deprecation message to use for trigger_error().
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static array $deprecatedState = [
|
||||
'system.css_js_query_string' => [
|
||||
'replacement' => AssetQueryString::STATE_KEY,
|
||||
'message' => 'The \'system.css_js_query_string\' state is deprecated in drupal:10.2.0. Use \Drupal\Core\Asset\AssetQueryStringInterface::get() and ::reset() instead. See https://www.drupal.org/node/3358337.',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The key value store to use.
|
||||
*
|
||||
|
@ -38,6 +55,13 @@ class State extends CacheCollector implements StateInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key, $default = NULL) {
|
||||
// If the caller is asking for the value of a deprecated state, trigger a
|
||||
// deprecation message about it.
|
||||
if (isset(self::$deprecatedState[$key])) {
|
||||
// phpcs:ignore Drupal.Semantics.FunctionTriggerError
|
||||
@trigger_error(self::$deprecatedState[$key]['message'], E_USER_DEPRECATED);
|
||||
$key = self::$deprecatedState[$key]['replacement'];
|
||||
}
|
||||
return parent::get($key) ?? $default;
|
||||
}
|
||||
|
||||
|
@ -67,6 +91,11 @@ class State extends CacheCollector implements StateInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
if (isset(self::$deprecatedState[$key])) {
|
||||
// phpcs:ignore Drupal.Semantics.FunctionTriggerError
|
||||
@trigger_error(self::$deprecatedState[$key]['message'], E_USER_DEPRECATED);
|
||||
$key = self::$deprecatedState[$key]['replacement'];
|
||||
}
|
||||
$this->keyValueStore->set($key, $value);
|
||||
// If another request had a cache miss before this request, and also hasn't
|
||||
// written to cache yet, then it may already have read this value from the
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\KernelTests\Core\State;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the legacy state deprecations.
|
||||
*
|
||||
* @group system
|
||||
* @group legacy
|
||||
* @coversDefaultClass \Drupal\Core\State\State
|
||||
*/
|
||||
class LegacyStateTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* @covers ::get
|
||||
* @covers ::set
|
||||
*/
|
||||
public function testDeprecatedState(): void {
|
||||
$state = $this->container->get('state');
|
||||
$this->expectDeprecation('The \'system.css_js_query_string\' state is deprecated in drupal:10.2.0. Use \Drupal\Core\Asset\AssetQueryStringInterface::get() and ::reset() instead. See https://www.drupal.org/node/3358337.');
|
||||
$state->set('system.css_js_query_string', 'foo');
|
||||
$this->expectDeprecation('The \'system.css_js_query_string\' state is deprecated in drupal:10.2.0. Use \Drupal\Core\Asset\AssetQueryStringInterface::get() and ::reset() instead. See https://www.drupal.org/node/3358337.');
|
||||
$this->assertEquals('foo', $state->get('system.css_js_query_string'));
|
||||
$this->assertEquals('foo', \Drupal::service('asset.query_string')->get());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue