Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | namespace LdapRecord\Models\ActiveDirectory\Scopes; |
| 4 | |
| 5 | use LdapRecord\Models\ActiveDirectory\Entry; |
| 6 | use LdapRecord\Models\Model; |
| 7 | use LdapRecord\Models\Scope; |
| 8 | use LdapRecord\Query\Model\Builder; |
| 9 | |
| 10 | class 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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 18 | * @return void |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 19 | * |
| 20 | * @throws \LdapRecord\Models\ModelNotFoundException |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 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 | * |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 32 | * @return mixed |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 33 | * |
| 34 | * @throws \LdapRecord\Models\ModelNotFoundException |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 35 | */ |
| 36 | protected function getConfigurationNamingContext(Model $model) |
| 37 | { |
| 38 | return Entry::getRootDse($model->getConnectionName()) |
| 39 | ->getFirstAttribute('configurationNamingContext'); |
| 40 | } |
| 41 | } |