[ticket/9687] Use cache driver instead of service

PHPBB3-9687
This commit is contained in:
Marc Alexander 2023-07-30 10:08:44 +02:00
parent 2d53b8f947
commit 927f33fad3
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
6 changed files with 22 additions and 63 deletions

View file

@ -4,7 +4,7 @@ services:
class: \phpbb\ban\manager
arguments:
- '@ban.type_collection'
- '@cache'
- '@cache.driver'
- '@dbal.conn'
- '@user'
- '%tables.bans%'

View file

@ -16,6 +16,10 @@ namespace phpbb\ban;
use phpbb\ban\exception\invalid_length_exception;
use phpbb\ban\exception\type_not_found_exception;
use phpbb\ban\type\type_interface;
use phpbb\cache\driver\driver_interface as cache_driver;
use phpbb\db\driver\driver_interface;
use phpbb\di\service_collection;
use phpbb\user;
class manager
{
@ -26,16 +30,16 @@ class manager
/** @var string */
protected $bans_table;
/** @var \phpbb\cache\service */
/** @var cache_driver */
protected $cache;
/** @var \phpbb\db\driver\driver_interface */
/** @var driver_interface */
protected $db;
/** @var \phpbb\di\service_collection */
/** @var service_collection */
protected $types;
/** @var \phpbb\user */
/** @var user */
protected $user;
/** @var string */
@ -45,14 +49,14 @@ class manager
* Creates a service which manages all bans. Developers can
* create their own ban types which will be handled in this.
*
* @param \phpbb\di\service_collection $types A service collection containing all ban types
* @param \phpbb\cache\service $cache A cache object
* @param \phpbb\db\driver\driver_interface $db A phpBB DBAL object
* @param \phpbb\user $user User object
* @param string $bans_table The bans table
* @param string $users_table The users table
* @param service_collection $types A service collection containing all ban types
* @param cache_driver $cache A cache object
* @param driver_interface $db A phpBB DBAL object
* @param user $user User object
* @param string $bans_table The bans table
* @param string $users_table The users table
*/
public function __construct($types, \phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $bans_table, $users_table = '')
public function __construct(service_collection $types, cache_driver $cache, driver_interface $db, user $user, string $bans_table, string $users_table = '')
{
$this->bans_table = $bans_table;
$this->cache = $cache;

View file

@ -36,18 +36,6 @@ class ban_manager_test extends \phpbb_session_test_case
$config = new \phpbb\config\config([]);
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
// Change the global cache object for this test because
// the mock cache object does not hit the database as is needed
// for this test.
$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\dummy(),
$config,
$this->db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$phpbb_container = new \phpbb_mock_container_builder();
$ban_type_email = new \phpbb\ban\type\email($this->db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$ban_type_user = new \phpbb\ban\type\user($this->db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
@ -60,7 +48,7 @@ class ban_manager_test extends \phpbb_session_test_case
$collection->add('ban.type.user');
$collection->add('ban.type.ip');
$this->ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, $user, 'phpbb_bans', 'phpbb_users');
$this->ban_manager = new \phpbb\ban\manager($collection, new \phpbb\cache\driver\dummy(), $this->db, $user, 'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $this->ban_manager);
$this->phpbb_container = $phpbb_container;
}
@ -385,19 +373,7 @@ class ban_manager_test extends \phpbb_session_test_case
$config = new \phpbb\config\config([]);
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
// Change the global cache object for this test because
// the mock cache object does not hit the database as is needed
// for this test.
$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\dummy(),
$config,
$this->db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, $user, 'phpbb_bans', 'phpbb_users');
$ban_manager = new \phpbb\ban\manager($collection, new \phpbb\cache\driver\dummy(), $this->db, $user, 'phpbb_bans', 'phpbb_users');
$this->assertEquals(
[
@ -442,19 +418,7 @@ class ban_manager_test extends \phpbb_session_test_case
$config = new \phpbb\config\config([]);
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
// Change the global cache object for this test because
// the mock cache object does not hit the database as is needed
// for this test.
$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\dummy(),
$config,
$this->db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, $user, 'phpbb_bans', 'phpbb_users');
$ban_manager = new \phpbb\ban\manager($collection, new \phpbb\cache\driver\dummy(), $this->db, $user, 'phpbb_bans', 'phpbb_users');
$start_time = new \DateTime();
$start_time->setTimestamp(1000);

View file

@ -62,7 +62,7 @@ class phpbb_functions_validate_user_email_test extends phpbb_database_test_case
$collection->add('ban.type.user');
$collection->add('ban.type.ip');
$ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, $this->user, 'phpbb_bans', 'phpbb_users');
$ban_manager = new \phpbb\ban\manager($collection, $cache->get_driver(), $this->db, $this->user, 'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $ban_manager);
}

View file

@ -87,7 +87,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case
$collection->add('ban.type.user');
$collection->add('ban.type.ip');
$ban_manager = new \phpbb\ban\manager($collection, $cache, $this->db, $user, 'phpbb_bans', 'phpbb_users');
$ban_manager = new \phpbb\ban\manager($collection, $cache->get_driver(), $this->db, $user, 'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $ban_manager);
}

View file

@ -109,15 +109,6 @@ class phpbb_session_testable_factory
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$cache_service = new \phpbb\cache\service(
$cache,
$config,
$db,
$phpbb_dispatcher,
$phpbb_root_path,
$phpEx
);
$ban_type_email = new \phpbb\ban\type\email($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$ban_type_user = new \phpbb\ban\type\user($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
$ban_type_ip = new \phpbb\ban\type\ip($db, 'phpbb_bans', 'phpbb_users', 'phpbb_sessions', 'phpbb_sessions_keys');
@ -130,7 +121,7 @@ class phpbb_session_testable_factory
$collection->add('ban.type.user');
$collection->add('ban.type.ip');
$ban_manager = new \phpbb\ban\manager($collection, $cache_service, $db, $user,'phpbb_bans', 'phpbb_users');
$ban_manager = new \phpbb\ban\manager($collection, $cache, $db, $user,'phpbb_bans', 'phpbb_users');
$phpbb_container->set('ban.manager', $ban_manager);
$session = new phpbb_mock_session_testable;