fix: Use proper DI for LDAP class

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-02-26 15:21:40 +01:00
parent cc365554c6
commit 60c86848e4
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
3 changed files with 15 additions and 13 deletions

View file

@ -53,11 +53,7 @@ class Application extends App implements IBootstrap {
}
public function register(IRegistrationContext $context): void {
$context->registerService(ILDAPWrapper::class, function (ContainerInterface $c) {
return new LDAP(
$c->get(IConfig::class)->getSystemValueString('ldap_log_file')
);
});
$context->registerServiceAlias(ILDAPWrapper::class, LDAP::class);
$context->registerNotifierService(Notifier::class);

View file

@ -18,23 +18,21 @@ use Psr\Log\LoggerInterface;
class LDAP implements ILDAPWrapper {
protected array $curArgs = [];
protected LoggerInterface $logger;
protected IConfig $config;
private ?LdapDataCollector $dataCollector = null;
protected string $logFile = '';
public function __construct(
protected string $logFile = '',
IProfiler $profiler,
protected IConfig $config,
protected LoggerInterface $logger,
) {
/** @var IProfiler $profiler */
$profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$this->dataCollector = new LdapDataCollector();
$profiler->add($this->dataCollector);
}
$this->logger = Server::get(LoggerInterface::class);
$this->config = Server::get(IConfig::class);
$this->logFile = $this->config->getSystemValueString('ldap_log_file');
}
/**

View file

@ -8,7 +8,10 @@ declare(strict_types=1);
namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\LDAP;
use OCP\IConfig;
use OCP\Profiler\IProfiler;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class LDAPTest extends TestCase {
@ -18,6 +21,11 @@ class LDAPTest extends TestCase {
parent::setUp();
$this->ldap = $this->getMockBuilder(LDAP::class)
->onlyMethods(['invokeLDAPMethod'])
->setConstructorArgs([
$this->createMock(IProfiler::class),
$this->createMock(IConfig::class),
$this->createMock(LoggerInterface::class),
])
->getMock();
}