From 4130a4cbd8e5bb4506ac30a19a91b088aa35dd24 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Mon, 24 Oct 2022 16:09:06 +0200 Subject: Make sure to use AccessFactory to create Access instances and use DI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Proxy.php | 46 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'apps/user_ldap/lib/Proxy.php') diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php index 4df6c2683a6..8cdb1b1da6a 100644 --- a/apps/user_ldap/lib/Proxy.php +++ b/apps/user_ldap/lib/Proxy.php @@ -34,57 +34,41 @@ namespace OCA\User_LDAP; use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; -use OCA\User_LDAP\User\Manager; -use OCP\IConfig; -use OCP\IUserManager; +use OCP\ICache; use OCP\Server; -use Psr\Log\LoggerInterface; abstract class Proxy { - private static $accesses = []; - private $ldap = null; - /** @var bool */ - private $isSingleBackend; - - /** @var \OCP\ICache|null */ - private $cache; - - /** - * @param ILDAPWrapper $ldap - */ - public function __construct(ILDAPWrapper $ldap) { + /** @var array */ + private static array $accesses = []; + private ILDAPWrapper $ldap; + private ?bool $isSingleBackend = null; + private ?ICache $cache = null; + private AccessFactory $accessFactory; + + public function __construct( + ILDAPWrapper $ldap, + AccessFactory $accessFactory + ) { $this->ldap = $ldap; + $this->accessFactory = $accessFactory; $memcache = \OC::$server->getMemCacheFactory(); if ($memcache->isAvailable()) { $this->cache = $memcache->createDistributed(); } } - /** - * @param string $configPrefix - */ private function addAccess(string $configPrefix): void { - $ocConfig = Server::get(IConfig::class); $userMap = Server::get(UserMapping::class); $groupMap = Server::get(GroupMapping::class); - $coreUserManager = Server::get(IUserManager::class); - $logger = Server::get(LoggerInterface::class); - $helper = Server::get(Helper::class); - - $userManager = Server::get(Manager::class); $connector = new Connection($this->ldap, $configPrefix); - $access = new Access($connector, $this->ldap, $userManager, $helper, $ocConfig, $coreUserManager, $logger); + $access = $this->accessFactory->get($connector); $access->setUserMapper($userMap); $access->setGroupMapper($groupMap); self::$accesses[$configPrefix] = $access; } - /** - * @param string $configPrefix - * @return mixed - */ - protected function getAccess($configPrefix) { + protected function getAccess(string $configPrefix): Access { if (!isset(self::$accesses[$configPrefix])) { $this->addAccess($configPrefix); } -- cgit v1.2.3