Move getBaseDN to Entry class, some cleanup
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Ldap;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use LdapRecord\Models\Model;
|
||||
use LdapRecord\Models\ModelNotFoundException;
|
||||
use LdapRecord\Query\Model\Builder;
|
||||
|
||||
class Entry extends Model
|
||||
{
|
||||
@@ -13,10 +16,39 @@ class Entry extends Model
|
||||
*/
|
||||
public static $objectClasses = [];
|
||||
|
||||
public function rootDSE($connection = null)
|
||||
/**
|
||||
* Gets the root DN of the specified LDAPServer, or throws an exception if it
|
||||
* can't find it.
|
||||
*
|
||||
* @param null $connection
|
||||
* @return Collection
|
||||
* @throws ModelNotFoundException
|
||||
* @testedin GetBaseDNTest::testBaseDNExists();
|
||||
*/
|
||||
public function baseDN($connection = NULL): ?Collection
|
||||
{
|
||||
$base = static::on($connection ?? (new static)->getConnectionName())
|
||||
->in(NULL)
|
||||
->read()
|
||||
->select(['namingcontexts'])
|
||||
->whereHas('objectclass')
|
||||
->firstOrFail();
|
||||
|
||||
return $base->namingcontexts ? collect($base->namingcontexts) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the rootDSE for the server, that gives us server information
|
||||
*
|
||||
* @param null $connection
|
||||
* @return Entry|null
|
||||
* @throws ModelNotFoundException
|
||||
* @testedin TranslateOidTest::testRootDSE();
|
||||
*/
|
||||
public function rootDSE($connection = NULL): ?Entry
|
||||
{
|
||||
return static::on($connection ?? (new static)->getConnectionName())
|
||||
->in(null)
|
||||
->in(NULL)
|
||||
->read()
|
||||
->select(['+'])
|
||||
->whereHas('objectclass')
|
||||
|
Reference in New Issue
Block a user