This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/28-user-interface-and-factory'
- Loading branch information
Showing
24 changed files
with
663 additions
and
171 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
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,68 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zend\Expressive\Authentication; | ||
|
||
/** | ||
* Default implementation of UserInterface. | ||
* | ||
* This implementation is modeled as immutable, to prevent propagation of | ||
* user state changes. | ||
* | ||
* We recommend that any details injected are serializable. | ||
*/ | ||
final class DefaultUser implements UserInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $identity; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $roles; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $details; | ||
|
||
public function __construct(string $identity, array $roles = [], array $details = []) | ||
{ | ||
$this->identity = $identity; | ||
$this->roles = $roles; | ||
$this->details = $details; | ||
} | ||
|
||
public function getIdentity() : string | ||
{ | ||
return $this->identity; | ||
} | ||
|
||
public function getRoles() : array | ||
{ | ||
return $this->roles; | ||
} | ||
|
||
public function getDetails() : array | ||
{ | ||
return $this->details; | ||
} | ||
|
||
/** | ||
* @param mixed $default Default value to return if no detail matching | ||
* $name is discovered. | ||
* @return mixed | ||
*/ | ||
public function getDetail(string $name, $default = null) | ||
{ | ||
return $this->details[$name] ?? $default; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zend\Expressive\Authentication; | ||
|
||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Produces a callable factory capable of itself producing a UserInterface | ||
* instance; this approach is used to allow substituting alternative user | ||
* implementations without requiring extensions to existing repositories. | ||
*/ | ||
class DefaultUserFactory | ||
{ | ||
public function __invoke(ContainerInterface $container) : callable | ||
{ | ||
return function (string $identity, array $roles = [], array $details = []) : UserInterface { | ||
return new DefaultUser($identity, $roles, $details); | ||
}; | ||
} | ||
} |
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.