-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted importing for ability to use any model
- Loading branch information
1 parent
4a655c7
commit fe9d707
Showing
14 changed files
with
622 additions
and
441 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
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,73 @@ | ||
<?php | ||
|
||
namespace LdapRecord\Laravel; | ||
|
||
use LdapRecord\Models\Model as LdapModel; | ||
use Illuminate\Database\Eloquent\Model as EloquentModel; | ||
|
||
class EloquentHydrator | ||
{ | ||
/** | ||
* The configuration to pass to each hydrator. | ||
* | ||
* @var array | ||
*/ | ||
protected $config = []; | ||
|
||
/** | ||
* Extra data to pass to each hydrator. | ||
* | ||
* @var array | ||
*/ | ||
protected $data = []; | ||
|
||
/** | ||
* The hydrators to use when importing. | ||
* | ||
* @var array | ||
*/ | ||
protected $hydrators = [ | ||
Hydrators\GuidHydrator::class, | ||
Hydrators\DomainHydrator::class, | ||
Hydrators\AttributeHydrator::class, | ||
]; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config = []) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Extra data to pass to each hydrator. | ||
* | ||
* @param array $data | ||
* | ||
* @return $this | ||
*/ | ||
public function with(array $data = []) | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Hydrate the database model with the LDAP user. | ||
* | ||
* @param LdapModel $user | ||
* @param EloquentModel $database | ||
* | ||
* @return void | ||
*/ | ||
public function hydrate(LdapModel $user, EloquentModel $database) | ||
{ | ||
foreach ($this->hydrators as $hydrator) { | ||
$hydrator::with($this->config, $this->data)->hydrate($user, $database); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.