This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to use a custom user import scope
Closes #699
- Loading branch information
1 parent
6ca2c46
commit d41c4a4
Showing
2 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Adldap\Laravel\Commands; | ||
|
||
use Adldap\Laravel\Facades\Resolver; | ||
use Illuminate\Database\Eloquent\Scope; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class UserImportScope implements Scope | ||
{ | ||
/** | ||
* The LDAP users object guid. | ||
* | ||
* @var string | ||
*/ | ||
protected $guid; | ||
|
||
/** | ||
* The LDAP users username. | ||
* | ||
* @var string | ||
*/ | ||
protected $username; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $guid | ||
* @param string $username | ||
*/ | ||
public function __construct($guid, $username) | ||
{ | ||
$this->guid = $guid; | ||
$this->username = $username; | ||
} | ||
|
||
/** | ||
* Apply the scope to a given Eloquent query builder. | ||
* | ||
* @param Builder $query | ||
* @param Model $model | ||
* | ||
* @return void | ||
*/ | ||
public function apply(Builder $query, Model $model) | ||
{ | ||
// We'll try to locate the user by their object guid, | ||
// otherwise we'll locate them by their username. | ||
$query | ||
->where(Resolver::getDatabaseIdColumn(), '=', $this->getGuid()) | ||
->orWhere(Resolver::getDatabaseUsernameColumn(), '=', $this->getUsername()); | ||
} | ||
|
||
/** | ||
* Returns the users object guid. | ||
* | ||
* @return string | ||
*/ | ||
protected function getGuid() | ||
{ | ||
return $this->guid; | ||
} | ||
|
||
/** | ||
* Returns the LDAP users username. | ||
* | ||
* @return string | ||
*/ | ||
protected function getUsername() | ||
{ | ||
return $this->username; | ||
} | ||
} |