blob: 2b1a177b06d8f1a9ffaaf5659f81dadd5083659c [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 *
18 * @throws \LdapRecord\Models\ModelNotFoundException
19 *
20 * @return void
21 */
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 *
32 * @throws \LdapRecord\Models\ModelNotFoundException
33 *
34 * @return mixed
35 */
36 protected function getConfigurationNamingContext(Model $model)
37 {
38 return Entry::getRootDse($model->getConnectionName())
39 ->getFirstAttribute('configurationNamingContext');
40 }
41}