Skip to content

Commit a9e38fb

Browse files
committed
fix(crl): move ldap extension check from constructor to connect()
Throwing in the constructor of PhpLdapConnection crashed the DI container on every request on servers that do not have the php-ldap extension installed, even when no LDAP CRL URL was being checked. Moving the guard to connect() keeps instantiation safe and lets the existing RuntimeException catch-block in fetchFromLdap log a warning and return null gracefully instead. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent a112b35 commit a9e38fb

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

lib/Service/Crl/Ldap/PhpLdapConnection.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@
1313
* Production implementation of ILdapConnection that delegates every call
1414
* to the corresponding PHP ldap_* function.
1515
*
16-
* Requires the PHP ldap extension to be loaded. If the extension is missing
17-
* the constructor throws so the DI container can catch the problem early
18-
* rather than failing silently at connection time.
16+
* If the PHP ldap extension is absent the class can still be instantiated;
17+
* callers are expected to check function_exists('ldap_connect') before use.
1918
*/
2019
class PhpLdapConnection implements ILdapConnection {
21-
public function __construct() {
22-
if (!function_exists('ldap_connect')) {
23-
throw new \RuntimeException('PHP ldap extension is not loaded');
24-
}
25-
}
2620

2721
#[\Override]
2822
public function connect(string $host, int $port): mixed {
23+
if (!function_exists('ldap_connect')) {
24+
throw new \RuntimeException('PHP ldap extension is not loaded');
25+
}
2926
$conn = @ldap_connect($host, $port);
3027
if (!$conn) {
3128
throw new \RuntimeException(sprintf('ldap_connect failed for %s:%d', $host, $port));

0 commit comments

Comments
 (0)