Skip to content

Commit badbf99

Browse files
authored
Merge pull request #788 from DirectoryTree/query-builder-grammar-fixes
Refactor query filters to use composable filter objects
2 parents c22323a + 24f1831 commit badbf99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1295
-1170
lines changed

src/Ldap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getAttributes(mixed $entry): array|false
6262
}
6363

6464
/**
65-
* {@inheritDoc}
65+
* {@inheritdoc}
6666
*/
6767
public function countEntries(mixed $result): int
6868
{
@@ -72,7 +72,7 @@ public function countEntries(mixed $result): int
7272
}
7373

7474
/**
75-
* {@inheritDoc}
75+
* {@inheritdoc}
7676
*/
7777
public function compare(string $dn, string $attribute, string $value, ?array $controls = null): bool|int
7878
{
@@ -108,7 +108,7 @@ public function getDetailedError(): ?DetailedError
108108
}
109109

110110
/**
111-
* {@inheritDoc}
111+
* {@inheritdoc}
112112
*/
113113
public function getValuesLen(mixed $entry, string $attribute): array|false
114114
{
@@ -285,7 +285,7 @@ public function bind(?string $dn = null, ?string $password = null, ?array $contr
285285
}
286286

287287
/**
288-
* {@inheritDoc}
288+
* {@inheritdoc}
289289
*/
290290
public function saslBind(?string $dn = null, ?string $password = null, array $options = []): bool
291291
{

src/Models/Attributes/TSProperty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ protected function packBitString(string $bits, int $len): string
282282
$nibbles[$i] = base_convert($nibble, 2, 16);
283283
}
284284

285-
return pack('H*', implode('', $nibbles));
285+
return pack('H*', implode($nibbles));
286286
}
287287

288288
/**

src/Models/Model.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,33 +375,38 @@ public static function unsetConnectionContainer(): void
375375
*/
376376
public function registerModelScopes(Builder $query): Builder
377377
{
378-
$this->applyObjectClassScopes($query);
378+
$this->registerObjectClassScopes($query);
379379

380380
$this->registerGlobalScopes($query);
381381

382382
return $query;
383383
}
384384

385385
/**
386-
* Register the global model scopes.
386+
* Register the object class scopes for this builder instance.
387387
*/
388-
public function registerGlobalScopes(Builder $query): Builder
388+
public function registerObjectClassScopes(Builder $query): Builder
389389
{
390-
foreach ($this->getGlobalScopes() as $identifier => $scope) {
391-
$query->withGlobalScope($identifier, $scope);
390+
if (static::$objectClasses) {
391+
$query->withGlobalScope(
392+
Scopes\HasObjectClasses::class,
393+
new Scopes\HasObjectClasses
394+
);
392395
}
393396

394397
return $query;
395398
}
396399

397400
/**
398-
* Apply the model object class scopes to the given builder instance.
401+
* Register the global model scopes.
399402
*/
400-
public function applyObjectClassScopes(Builder $query): void
403+
public function registerGlobalScopes(Builder $query): Builder
401404
{
402-
foreach (static::$objectClasses as $objectClass) {
403-
$query->where('objectclass', '=', $objectClass);
405+
foreach ($this->getGlobalScopes() as $identifier => $scope) {
406+
$query->withGlobalScope($identifier, $scope);
404407
}
408+
409+
return $query;
405410
}
406411

407412
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace LdapRecord\Models\Scopes;
4+
5+
use LdapRecord\Models\Model;
6+
use LdapRecord\Models\Scope;
7+
use LdapRecord\Query\Model\Builder;
8+
9+
class HasObjectClasses implements Scope
10+
{
11+
/**
12+
* Restrict the query to the model's object classes.
13+
*/
14+
public function apply(Builder $query, Model $model): void
15+
{
16+
foreach ($model::$objectClasses as $objectClass) {
17+
$query->where('objectclass', '=', $objectClass);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)