blob: 9f2fbe4d7dde46681e31c5e630c688899654dec2 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord\Models\ActiveDirectory\Scopes;
4
5use LdapRecord\Models\ActiveDirectory\Entry;
6use LdapRecord\Models\Model;
7use LdapRecord\Models\Scope;
8use LdapRecord\Query\Model\Builder;
9
10class InConfigurationContext implements Scope
11{
12 /**
13 * Refines the base dn to be inside the configuration context.
14 *
15 * @param Builder $query
16 * @param Model $model
17 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020018 * @return void
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010019 *
20 * @throws \LdapRecord\Models\ModelNotFoundException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020021 */
22 public function apply(Builder $query, Model $model)
23 {
24 $query->in($this->getConfigurationNamingContext($model));
25 }
26
27 /**
28 * Get the LDAP server configuration naming context distinguished name.
29 *
30 * @param Model $model
31 *
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020032 * @return mixed
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010033 *
34 * @throws \LdapRecord\Models\ModelNotFoundException
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020035 */
36 protected function getConfigurationNamingContext(Model $model)
37 {
38 return Entry::getRootDse($model->getConnectionName())
39 ->getFirstAttribute('configurationNamingContext');
40 }
41}