| @@ 34-113 (lines=80) @@ | ||
| 31 | /** |
|
| 32 | * @package Limoncello\Passport |
|
| 33 | */ |
|
| 34 | class MySqlPassportContainerConfigurator extends BasePassportContainerConfigurator implements CCI |
|
| 35 | { |
|
| 36 | /** |
|
| 37 | * @inheritdoc |
|
| 38 | * |
|
| 39 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
|
| 40 | */ |
|
| 41 | public static function configureContainer(LimoncelloContainerInterface $container) |
|
| 42 | { |
|
| 43 | static::baseConfigureContainer($container); |
|
| 44 | ||
| 45 | $container[PassportServerIntegrationInterface::class] = function (PsrContainerInterface $container) { |
|
| 46 | assert($container !== null); |
|
| 47 | ||
| 48 | return new class ($container) extends MySqlPassportServerIntegration |
|
| 49 | { |
|
| 50 | /** |
|
| 51 | * @var PsrContainerInterface |
|
| 52 | */ |
|
| 53 | private $container; |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @var array |
|
| 57 | */ |
|
| 58 | private $settings; |
|
| 59 | ||
| 60 | /** |
|
| 61 | * @param PsrContainerInterface $container |
|
| 62 | */ |
|
| 63 | public function __construct(PsrContainerInterface $container) |
|
| 64 | { |
|
| 65 | $this->container = $container; |
|
| 66 | $this->settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 67 | ||
| 68 | /** @var Connection $connection */ |
|
| 69 | $connection = $container->get(Connection::class); |
|
| 70 | ||
| 71 | parent::__construct( |
|
| 72 | $connection, |
|
| 73 | $this->settings[C::KEY_DEFAULT_CLIENT_ID], |
|
| 74 | $this->settings[C::KEY_APPROVAL_URI_STRING], |
|
| 75 | $this->settings[C::KEY_ERROR_URI_STRING], |
|
| 76 | $this->settings[C::KEY_CODE_EXPIRATION_TIME_IN_SECONDS], |
|
| 77 | $this->settings[C::KEY_TOKEN_EXPIRATION_TIME_IN_SECONDS], |
|
| 78 | $this->settings[C::KEY_RENEW_REFRESH_VALUE_ON_TOKEN_REFRESH] |
|
| 79 | ); |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @inheritdoc |
|
| 84 | */ |
|
| 85 | public function validateUserId(string $userName, string $password) |
|
| 86 | { |
|
| 87 | $validator = $this->settings[C::KEY_USER_CREDENTIALS_VALIDATOR]; |
|
| 88 | $nullOrUserId = call_user_func($validator, $this->container, $userName, $password); |
|
| 89 | ||
| 90 | return $nullOrUserId; |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * @inheritdoc |
|
| 95 | */ |
|
| 96 | public function verifyAllowedUserScope(int $userIdentity, array $scope = null) |
|
| 97 | { |
|
| 98 | $validator = $this->settings[C::KEY_USER_SCOPE_VALIDATOR]; |
|
| 99 | $nullOrScope = call_user_func($validator, $this->container, $userIdentity, $scope); |
|
| 100 | ||
| 101 | return $nullOrScope; |
|
| 102 | } |
|
| 103 | }; |
|
| 104 | }; |
|
| 105 | ||
| 106 | $container[TokenRepositoryInterface::class] = function (PsrContainerInterface $container) { |
|
| 107 | $connection = $container->get(Connection::class); |
|
| 108 | $scheme = $container->get(DatabaseSchemeInterface::class); |
|
| 109 | ||
| 110 | return new TokenRepository($connection, $scheme); |
|
| 111 | }; |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||
| @@ 34-113 (lines=80) @@ | ||
| 31 | /** |
|
| 32 | * @package Limoncello\Passport |
|
| 33 | */ |
|
| 34 | class PassportContainerConfigurator extends BasePassportContainerConfigurator implements ContainerConfiguratorInterface |
|
| 35 | { |
|
| 36 | /** |
|
| 37 | * @inheritdoc |
|
| 38 | * |
|
| 39 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
|
| 40 | */ |
|
| 41 | public static function configureContainer(LimoncelloContainerInterface $container) |
|
| 42 | { |
|
| 43 | static::baseConfigureContainer($container); |
|
| 44 | ||
| 45 | $container[PassportServerIntegrationInterface::class] = function (PsrContainerInterface $container) { |
|
| 46 | assert($container !== null); |
|
| 47 | ||
| 48 | return new class ($container) extends GenericPassportServerIntegration |
|
| 49 | { |
|
| 50 | /** |
|
| 51 | * @var PsrContainerInterface |
|
| 52 | */ |
|
| 53 | private $container; |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @var array |
|
| 57 | */ |
|
| 58 | private $settings; |
|
| 59 | ||
| 60 | /** |
|
| 61 | * @param PsrContainerInterface $container |
|
| 62 | */ |
|
| 63 | public function __construct(PsrContainerInterface $container) |
|
| 64 | { |
|
| 65 | $this->container = $container; |
|
| 66 | $this->settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 67 | ||
| 68 | /** @var Connection $connection */ |
|
| 69 | $connection = $container->get(Connection::class); |
|
| 70 | ||
| 71 | parent::__construct( |
|
| 72 | $connection, |
|
| 73 | $this->settings[C::KEY_DEFAULT_CLIENT_ID], |
|
| 74 | $this->settings[C::KEY_APPROVAL_URI_STRING], |
|
| 75 | $this->settings[C::KEY_ERROR_URI_STRING], |
|
| 76 | $this->settings[C::KEY_CODE_EXPIRATION_TIME_IN_SECONDS], |
|
| 77 | $this->settings[C::KEY_TOKEN_EXPIRATION_TIME_IN_SECONDS], |
|
| 78 | $this->settings[C::KEY_RENEW_REFRESH_VALUE_ON_TOKEN_REFRESH] |
|
| 79 | ); |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @inheritdoc |
|
| 84 | */ |
|
| 85 | public function validateUserId(string $userName, string $password) |
|
| 86 | { |
|
| 87 | $validator = $this->settings[C::KEY_USER_CREDENTIALS_VALIDATOR]; |
|
| 88 | $nullOrUserId = call_user_func($validator, $this->container, $userName, $password); |
|
| 89 | ||
| 90 | return $nullOrUserId; |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * @inheritdoc |
|
| 95 | */ |
|
| 96 | public function verifyAllowedUserScope(int $userIdentity, array $scope = null) |
|
| 97 | { |
|
| 98 | $validator = $this->settings[C::KEY_USER_SCOPE_VALIDATOR]; |
|
| 99 | $nullOrScope = call_user_func($validator, $this->container, $userIdentity, $scope); |
|
| 100 | ||
| 101 | return $nullOrScope; |
|
| 102 | } |
|
| 103 | }; |
|
| 104 | }; |
|
| 105 | ||
| 106 | $container[TokenRepositoryInterface::class] = function (PsrContainerInterface $container) { |
|
| 107 | $connection = $container->get(Connection::class); |
|
| 108 | $scheme = $container->get(DatabaseSchemeInterface::class); |
|
| 109 | ||
| 110 | return new TokenRepository($connection, $scheme); |
|
| 111 | }; |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||