AuthenticationServers.php in Lightweight Directory Access Protocol (LDAP) 8.4
File
ldap_authentication/src/AuthenticationServers.php
View source
<?php
declare (strict_types=1);
namespace Drupal\ldap_authentication;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
class AuthenticationServers {
protected $storage;
protected $config;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
$this->storage = $entity_type_manager
->getStorage('ldap_server');
$this->config = $config_factory
->get('ldap_authentication.settings');
}
public function authenticationServersAvailable() : bool {
if (empty($this
->getAvailableAuthenticationServers())) {
return FALSE;
}
return TRUE;
}
public function getAvailableAuthenticationServers() : array {
$available_servers = $this->storage
->getQuery()
->condition('status', 1)
->execute();
$result = [];
foreach ($this->config
->get('sids') as $configured_server) {
if (isset($available_servers[$configured_server])) {
$result[] = $configured_server;
}
}
return $result;
}
}