Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 0066a5a

Browse files
committed
Rework traits
- Removed UsesAdldap trait - Removed DispatchesAuthEvents trait
1 parent a141d1f commit 0066a5a

File tree

3 files changed

+54
-177
lines changed

3 files changed

+54
-177
lines changed

src/Traits/DispatchesAuthEvents.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Traits/UsesAdldap.php

Lines changed: 0 additions & 128 deletions
This file was deleted.

src/Traits/ValidatesUsers.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Adldap\Laravel\Traits;
4+
5+
use Adldap\Models\User;
6+
use Adldap\Laravel\Validation\Validator;
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
trait ValidatesUsers
10+
{
11+
/**
12+
* Determines if the model passes validation.
13+
*
14+
* @param User $user
15+
* @param Model $model
16+
*
17+
* @return bool
18+
*/
19+
protected function passesValidation(User $user, Model $model = null)
20+
{
21+
return $this->newValidator($this->getRules($user, $model))->passes();
22+
}
23+
24+
/**
25+
* Returns an array of constructed rules.
26+
*
27+
* @param User $user
28+
* @param Model|null $model
29+
*
30+
* @return array
31+
*/
32+
protected function getRules(User $user, Model $model = null)
33+
{
34+
$rules = [];
35+
36+
foreach (config('adldap_auth.rules', []) as $rule) {
37+
$rules[] = new $rule($user, $model);
38+
}
39+
40+
return $rules;
41+
}
42+
43+
/**
44+
* Returns a new authentication validator.
45+
*
46+
* @param array $rules
47+
*
48+
* @return Validator
49+
*/
50+
protected function newValidator(array $rules = [])
51+
{
52+
return new Validator($rules);
53+
}
54+
}

0 commit comments

Comments
 (0)