-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
236 additions
and
13 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,76 @@ | ||
<?php namespace Tatter\Users\Entities; | ||
|
||
use Fluent\Auth\Entities\User; | ||
use Tatter\Users\UserEntity; | ||
|
||
/** | ||
* Fluent User Entity | ||
*/ | ||
class FluentEntity extends User implements UserEntity | ||
{ | ||
/** | ||
* Returns the name of the column used to | ||
* uniquely identify this user, typically 'id'. | ||
* | ||
* @return string | ||
*/ | ||
public function getIdentifier(): string | ||
{ | ||
return $this->getAuthIdColumn(); | ||
} | ||
|
||
/** | ||
* Returns the value for the identifier, | ||
* or `null` for "uncreated" users. | ||
* | ||
* @return string|int|null | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->getAuthId(); | ||
} | ||
|
||
/** | ||
* Returns the email address. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getEmail(): ?string | ||
{ | ||
return $this->getAuthEmail(); | ||
} | ||
|
||
/** | ||
* Returns the username. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getUsername(): ?string | ||
{ | ||
return $this->attributes['username'] ?? null; | ||
} | ||
|
||
/** | ||
* Returns the name for this user. | ||
* If names are stored as parts "first", | ||
* "middle", "last" they should be | ||
* concatenated with spaces. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getName(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns whether this user is eligible | ||
* for authentication. | ||
* | ||
* @return bool | ||
*/ | ||
public function isActive(): bool | ||
{ | ||
return empty($this->attributes['deleted_at']); | ||
} | ||
} |
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,61 @@ | ||
<?php namespace Tatter\Users\Factories; | ||
|
||
use Fluent\Auth\Models\UserModel; | ||
use Tatter\Users\Entities\FluentEntity; | ||
use Tatter\Users\UserEntity; | ||
use Tatter\Users\UserFactory; | ||
|
||
/** | ||
* Fluent User Factory | ||
*/ | ||
class FluentFactory extends UserModel implements UserFactory | ||
{ | ||
/** | ||
* The format that the results should be returned as. | ||
* | ||
* @var string | ||
*/ | ||
protected $returnType = FluentEntity::class; | ||
|
||
/** | ||
* Locates a user by its primary identifier. | ||
* | ||
* @param string|int $id | ||
* | ||
* @return FluentEntity|null | ||
*/ | ||
public function findById($id): ?UserEntity | ||
{ | ||
/** @var FluentEntity|null $result */ | ||
$result = parent::findById($id); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Locates a user by its email. | ||
* | ||
* @param string $email | ||
* | ||
* @return FluentEntity|null | ||
*/ | ||
public function findByEmail(string $email): ?UserEntity | ||
{ | ||
/** @var FluentEntity|null $result */ | ||
$result = $this->findByCredentials(['email' => $email]); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Locates a user by its username. | ||
* | ||
* @param string $username | ||
* | ||
* @return FluentEntity|null | ||
*/ | ||
public function findByUsername(string $username): ?UserEntity | ||
{ | ||
/** @var FluentEntity|null $result */ | ||
$result = $this->findByCredentials(['username' => $username]); | ||
return $result; | ||
} | ||
} |
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,22 @@ | ||
<?php namespace Tatter\Users\Interfaces; | ||
|
||
use Tatter\Users\UserEntity; | ||
|
||
/** | ||
* Has Group Interface | ||
* | ||
* User extension for entities that | ||
* can verify group membership. | ||
*/ | ||
interface HasGroup extends UserEntity | ||
{ | ||
/** | ||
* Returns whether this user is a | ||
* member of the given group. | ||
* | ||
* @param string $group The group name | ||
* | ||
* @return bool | ||
*/ | ||
public function hasGroup(string $group): bool; | ||
} |
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,22 @@ | ||
<?php namespace Tatter\Users\Interfaces; | ||
|
||
use Tatter\Users\UserEntity; | ||
|
||
/** | ||
* Has Permission Interface | ||
* | ||
* User extension for entities that | ||
* can test a designated permission. | ||
*/ | ||
interface HasPermission extends UserEntity | ||
{ | ||
/** | ||
* Returns whether this user has | ||
* a certain permission. | ||
* | ||
* @param string $permission The permission name | ||
* | ||
* @return bool | ||
*/ | ||
public function hasPermission(string $permission): bool; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
use Fluent\Auth\Models\UserModel; | ||
use Tatter\Users\Factories\FluentFactory; | ||
use Tests\Support\FactoryTestCase; | ||
|
||
class FluentFactoryTest extends FactoryTestCase | ||
{ | ||
protected $namespace = 'Fluent\Auth'; | ||
protected $class = FluentFactory::class; | ||
protected $faker = UserModel::class; | ||
} |
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