@@ -55,8 +55,7 @@ discard block |
||
| 55 | 55 | * @class Loader |
| 56 | 56 | * @package Platine\Framework\Env |
| 57 | 57 | */ |
| 58 | -class Loader |
|
| 59 | -{
|
|
| 58 | +class Loader { |
|
| 60 | 59 | /** |
| 61 | 60 | * Put the parsed key value pair into |
| 62 | 61 | * $_ENV super global. |
@@ -92,7 +91,7 @@ discard block |
||
| 92 | 91 | bool $overwrite = false, |
| 93 | 92 | int $mode = self::PUTENV |
| 94 | 93 | ): void {
|
| 95 | - if (!is_file($file)) {
|
|
| 94 | + if (!is_file($file)) { |
|
| 96 | 95 | throw new InvalidArgumentException(sprintf( |
| 97 | 96 | 'The [%s] file does not exist or is not readable', |
| 98 | 97 | $file |
@@ -104,7 +103,7 @@ discard block |
||
| 104 | 103 | $content = (string) preg_replace('/^\s*#/m', ';', $fileContent);
|
| 105 | 104 | $parsed = parse_ini_string($content, false, INI_SCANNER_RAW); |
| 106 | 105 | |
| 107 | - if ($parsed === false) {
|
|
| 106 | + if ($parsed === false) { |
|
| 108 | 107 | throw new RuntimeException(sprintf( |
| 109 | 108 | 'The [%s] file cannot be parsed due to malformed values', |
| 110 | 109 | $file |
@@ -127,9 +126,9 @@ discard block |
||
| 127 | 126 | int $mode |
| 128 | 127 | ): void {
|
| 129 | 128 | $default = microtime(true); |
| 130 | - foreach ($vars as $key => $value) {
|
|
| 129 | + foreach ($vars as $key => $value) { |
|
| 131 | 130 | // Skip if we already have value and cant override. |
| 132 | - if (!$overwrite && $default !== Env::get($key, $default)) {
|
|
| 131 | + if (!$overwrite && $default !== Env::get($key, $default)) { |
|
| 133 | 132 | continue; |
| 134 | 133 | } |
| 135 | 134 | |
@@ -163,12 +162,12 @@ discard block |
||
| 163 | 162 | array $vars, |
| 164 | 163 | int $mode |
| 165 | 164 | ): void {
|
| 166 | - foreach ($vars as $key => $value) {
|
|
| 167 | - if (!$value || strpos($value, '${') === false) {
|
|
| 165 | + foreach ($vars as $key => $value) { |
|
| 166 | + if (!$value || strpos($value, '${') === false) { |
|
| 168 | 167 | continue; |
| 169 | 168 | } |
| 170 | 169 | |
| 171 | - $value = preg_replace_callback('~\$\{(\w+)\}~', function ($m) {
|
|
| 170 | + $value = preg_replace_callback('~\$\{(\w+)\}~', function ($m) { |
|
| 172 | 171 | return (null === $ref = Env::get($m[1], null)) ? $m[0] : $ref; |
| 173 | 172 | }, $value); |
| 174 | 173 | |
@@ -185,7 +184,7 @@ discard block |
||
| 185 | 184 | */ |
| 186 | 185 | protected function setValueEnv(string $key, string $value, int $mode): void |
| 187 | 186 | {
|
| 188 | - if ($mode & self::ENV) {
|
|
| 187 | + if ($mode & self::ENV) { |
|
| 189 | 188 | $_ENV[$key] = $value; |
| 190 | 189 | } |
| 191 | 190 | } |
@@ -199,7 +198,7 @@ discard block |
||
| 199 | 198 | */ |
| 200 | 199 | protected function setValueServer(string $key, string $value, int $mode): void |
| 201 | 200 | {
|
| 202 | - if ($mode & self::SERVER) {
|
|
| 201 | + if ($mode & self::SERVER) { |
|
| 203 | 202 | $_SERVER[$key] = $value; |
| 204 | 203 | } |
| 205 | 204 | } |
@@ -213,7 +212,7 @@ discard block |
||
| 213 | 212 | */ |
| 214 | 213 | protected function setValuePutenv(string $key, string $value, int $mode): void |
| 215 | 214 | {
|
| 216 | - if ($mode & self::PUTENV) {
|
|
| 215 | + if ($mode & self::PUTENV) { |
|
| 217 | 216 | putenv("$key=$value");
|
| 218 | 217 | } |
| 219 | 218 | } |
@@ -52,8 +52,7 @@ discard block |
||
| 52 | 52 | * @class Env |
| 53 | 53 | * @package Platine\Framework\Env |
| 54 | 54 | */ |
| 55 | -class Env |
|
| 56 | -{
|
|
| 55 | +class Env { |
|
| 57 | 56 | /** |
| 58 | 57 | * Get the environment variable by its key/name. |
| 59 | 58 | * @param string $key |
@@ -67,8 +66,8 @@ discard block |
||
| 67 | 66 | $default = null, |
| 68 | 67 | ?string $filter = null, |
| 69 | 68 | $options = 0 |
| 70 | - ) {
|
|
| 71 | - if ($filter !== null) {
|
|
| 69 | + ) { |
|
| 70 | + if ($filter !== null) { |
|
| 72 | 71 | $filterMaps = [ |
| 73 | 72 | 'bool' => FILTER_VALIDATE_BOOLEAN, |
| 74 | 73 | 'int' => FILTER_VALIDATE_INT, |
@@ -78,22 +77,22 @@ discard block |
||
| 78 | 77 | 'url' => FILTER_VALIDATE_URL, |
| 79 | 78 | ]; |
| 80 | 79 | |
| 81 | - if (isset($filterMaps[$filter])) {
|
|
| 80 | + if (isset($filterMaps[$filter])) { |
|
| 82 | 81 | $filter = $filterMaps[$filter]; |
| 83 | - } else {
|
|
| 82 | + } else { |
|
| 84 | 83 | $filter = null; |
| 85 | 84 | } |
| 86 | 85 | } |
| 87 | 86 | $value = getenv($key); |
| 88 | - if ($value !== false) {
|
|
| 87 | + if ($value !== false) { |
|
| 89 | 88 | return static::prepareValue($value, $filter, $options); |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | - if (isset($_ENV[$key])) {
|
|
| 91 | + if (isset($_ENV[$key])) { |
|
| 93 | 92 | return static::prepareValue($_ENV[$key], $filter, $options); |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | - if (isset($_SERVER[$key])) {
|
|
| 95 | + if (isset($_SERVER[$key])) { |
|
| 97 | 96 | return static::prepareValue($_SERVER[$key], $filter, $options); |
| 98 | 97 | } |
| 99 | 98 | |
@@ -113,7 +112,7 @@ discard block |
||
| 113 | 112 | string $value, |
| 114 | 113 | ?int $filter = null, |
| 115 | 114 | $options = 0 |
| 116 | - ) {
|
|
| 115 | + ) { |
|
| 117 | 116 | static $special = [ |
| 118 | 117 | 'true' => true, |
| 119 | 118 | 'TRUE' => true, |
@@ -126,11 +125,11 @@ discard block |
||
| 126 | 125 | $valueResolved = static::resolveReference($value); |
| 127 | 126 | |
| 128 | 127 | // strlen($valueResolved) < 6. |
| 129 | - if (!isset($valueResolved[5]) && array_key_exists($valueResolved, $special)) {
|
|
| 128 | + if (!isset($valueResolved[5]) && array_key_exists($valueResolved, $special)) { |
|
| 130 | 129 | return $special[$value]; |
| 131 | 130 | } |
| 132 | 131 | |
| 133 | - if ($filter === null || !function_exists('filter_var')) {
|
|
| 132 | + if ($filter === null || !function_exists('filter_var')) { |
|
| 134 | 133 | return $valueResolved; |
| 135 | 134 | } |
| 136 | 135 | |
@@ -144,15 +143,15 @@ discard block |
||
| 144 | 143 | */ |
| 145 | 144 | protected static function resolveReference(string $value): string |
| 146 | 145 | {
|
| 147 | - if (!$value || strpos($value, '${') === false) {
|
|
| 146 | + if (!$value || strpos($value, '${') === false) { |
|
| 148 | 147 | return $value; |
| 149 | 148 | } |
| 150 | 149 | |
| 151 | - $valueResolved = preg_replace_callback('~\$\{(\w+)\}~', function ($m) {
|
|
| 150 | + $valueResolved = preg_replace_callback('~\$\{(\w+)\}~', function ($m) { |
|
| 152 | 151 | return (null === $ref = static::get($m[1], null)) ? $m[0] : $ref; |
| 153 | 152 | }, $value); |
| 154 | 153 | |
| 155 | - if ($valueResolved !== null) {
|
|
| 154 | + if ($valueResolved !== null) { |
|
| 156 | 155 | return $valueResolved; |
| 157 | 156 | } |
| 158 | 157 | |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | * @class TokenOwner |
| 54 | 54 | * @package Platine\Framework\OAuth2\User |
| 55 | 55 | */ |
| 56 | -class TokenOwner implements TokenOwnerInterface |
|
| 57 | -{
|
|
| 56 | +class TokenOwner implements TokenOwnerInterface { |
|
| 58 | 57 | /** |
| 59 | 58 | * The owner id |
| 60 | 59 | * @var mixed |
@@ -65,16 +64,14 @@ discard block |
||
| 65 | 64 | * Create new instance |
| 66 | 65 | * @param mixed|null $id |
| 67 | 66 | */ |
| 68 | - public function __construct($id = null) |
|
| 69 | - {
|
|
| 67 | + public function __construct($id = null) { |
|
| 70 | 68 | $this->id = $id; |
| 71 | 69 | } |
| 72 | 70 | |
| 73 | 71 | /** |
| 74 | 72 | * {@inheritdoc}
|
| 75 | 73 | */ |
| 76 | - public function getOwnerId() |
|
| 77 | - {
|
|
| 74 | + public function getOwnerId() { |
|
| 78 | 75 | return $this->id; |
| 79 | 76 | } |
| 80 | 77 | } |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | * @class UserAuthentication |
| 57 | 57 | * @package Platine\Framework\OAuth2\User |
| 58 | 58 | */ |
| 59 | -class UserAuthentication implements UserAuthenticationInterface |
|
| 60 | -{
|
|
| 59 | +class UserAuthentication implements UserAuthenticationInterface { |
|
| 61 | 60 | /** |
| 62 | 61 | * The Authentication |
| 63 | 62 | * @var AuthenticationInterface |
@@ -68,8 +67,7 @@ discard block |
||
| 68 | 67 | * Create new instance |
| 69 | 68 | * @param AuthenticationInterface $authentication |
| 70 | 69 | */ |
| 71 | - public function __construct(AuthenticationInterface $authentication) |
|
| 72 | - {
|
|
| 70 | + public function __construct(AuthenticationInterface $authentication) { |
|
| 73 | 71 | $this->authentication = $authentication; |
| 74 | 72 | } |
| 75 | 73 | |
@@ -80,20 +78,20 @@ discard block |
||
| 80 | 78 | public function validate(string $username, string $password): ?TokenOwnerInterface |
| 81 | 79 | {
|
| 82 | 80 | $userId = null; |
| 83 | - try {
|
|
| 81 | + try { |
|
| 84 | 82 | $isLogged = $this->authentication->login([ |
| 85 | 83 | 'username' => $username, |
| 86 | 84 | 'password' => $password, |
| 87 | 85 | ]); |
| 88 | 86 | |
| 89 | - if ($isLogged) {
|
|
| 87 | + if ($isLogged) { |
|
| 90 | 88 | $userId = $this->authentication->getUser()->getId(); |
| 91 | 89 | } |
| 92 | - } catch (AuthenticationException $ex) {
|
|
| 90 | + } catch (AuthenticationException $ex) { |
|
| 93 | 91 | return null; |
| 94 | 92 | } |
| 95 | 93 | |
| 96 | - if ($userId === null) {
|
|
| 94 | + if ($userId === null) { |
|
| 97 | 95 | return null; |
| 98 | 96 | } |
| 99 | 97 | |
@@ -49,8 +49,7 @@ discard block |
||
| 49 | 49 | * @package Platine\Framework\OAuth2\Middleware |
| 50 | 50 | * @template T |
| 51 | 51 | */ |
| 52 | -class OauthResourceMiddleware implements MiddlewareInterface |
|
| 53 | -{
|
|
| 52 | +class OauthResourceMiddleware implements MiddlewareInterface { |
|
| 54 | 53 | /** |
| 55 | 54 | * The Resource Server |
| 56 | 55 | * @var ResourceServerInterface |
@@ -77,7 +76,7 @@ discard block |
||
| 77 | 76 | public function __construct( |
| 78 | 77 | ResourceServerInterface $resourceServer, |
| 79 | 78 | Config $config |
| 80 | - ) {
|
|
| 79 | + ) { |
|
| 81 | 80 | $this->resourceServer = $resourceServer; |
| 82 | 81 | $this->config = $config; |
| 83 | 82 | } |
@@ -89,16 +88,16 @@ discard block |
||
| 89 | 88 | ServerRequestInterface $request, |
| 90 | 89 | RequestHandlerInterface $handler |
| 91 | 90 | ): ResponseInterface {
|
| 92 | - if ($this->shouldBeProcessed($request) === false) {
|
|
| 91 | + if ($this->shouldBeProcessed($request) === false) { |
|
| 93 | 92 | return $handler->handle($request); |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | - try {
|
|
| 95 | + try { |
|
| 97 | 96 | $token = $this->resourceServer->getAccessToken($request, $this->scopes); |
| 98 | - if ($token === null) {
|
|
| 97 | + if ($token === null) { |
|
| 99 | 98 | throw InvalidAccessTokenException::invalidToken('No access token found in the request');
|
| 100 | 99 | } |
| 101 | - } catch (InvalidAccessTokenException $ex) {
|
|
| 100 | + } catch (InvalidAccessTokenException $ex) { |
|
| 102 | 101 | // If we're here, this means that there was an access token, but it's either expired |
| 103 | 102 | // or invalid. If that's the case we must immediately return |
| 104 | 103 | return new JsonResponse( |
@@ -123,7 +122,7 @@ discard block |
||
| 123 | 122 | //If no route has been match no need check |
| 124 | 123 | /** @var Route|null $route */ |
| 125 | 124 | $route = $request->getAttribute(Route::class); |
| 126 | - if ($route === null) {
|
|
| 125 | + if ($route === null) { |
|
| 127 | 126 | return false; |
| 128 | 127 | } |
| 129 | 128 | |
@@ -132,7 +131,7 @@ discard block |
||
| 132 | 131 | |
| 133 | 132 | //check if is url whitelist |
| 134 | 133 | $urls = $this->config->get('oauth2.url_whitelist', []);
|
| 135 | - if (in_array($route->getName(), $urls)) {
|
|
| 134 | + if (in_array($route->getName(), $urls)) { |
|
| 136 | 135 | return false; |
| 137 | 136 | } |
| 138 | 137 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | * @class AuthorizationRequestHandler |
| 44 | 44 | * @package Platine\Framework\OAuth2\Handler |
| 45 | 45 | */ |
| 46 | -class AuthorizationRequestHandler implements RequestHandlerInterface |
|
| 47 | -{
|
|
| 46 | +class AuthorizationRequestHandler implements RequestHandlerInterface { |
|
| 48 | 47 | /** |
| 49 | 48 | * The Authorization Server |
| 50 | 49 | * @var AuthorizationServerInterface |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | * Create new instance |
| 56 | 55 | * @param AuthorizationServerInterface $authorizationServer |
| 57 | 56 | */ |
| 58 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 59 | - {
|
|
| 57 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 60 | 58 | $this->authorizationServer = $authorizationServer; |
| 61 | 59 | } |
| 62 | 60 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | * @class AccessTokenRequestHandler |
| 44 | 44 | * @package Platine\Framework\OAuth2\Handler |
| 45 | 45 | */ |
| 46 | -class AccessTokenRequestHandler implements RequestHandlerInterface |
|
| 47 | -{
|
|
| 46 | +class AccessTokenRequestHandler implements RequestHandlerInterface { |
|
| 48 | 47 | /** |
| 49 | 48 | * The Authorization Server |
| 50 | 49 | * @var AuthorizationServerInterface |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | * Create new instance |
| 56 | 55 | * @param AuthorizationServerInterface $authorizationServer |
| 57 | 56 | */ |
| 58 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 59 | - {
|
|
| 57 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 60 | 58 | $this->authorizationServer = $authorizationServer; |
| 61 | 59 | } |
| 62 | 60 | |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | * @class TokenRevocationRequestHandler |
| 43 | 43 | * @package Platine\Framework\OAuth2\Handler |
| 44 | 44 | */ |
| 45 | -class TokenRevocationRequestHandler implements RequestHandlerInterface |
|
| 46 | -{
|
|
| 45 | +class TokenRevocationRequestHandler implements RequestHandlerInterface { |
|
| 47 | 46 | /** |
| 48 | 47 | * The Authorization Server |
| 49 | 48 | * @var AuthorizationServerInterface |
@@ -54,8 +53,7 @@ discard block |
||
| 54 | 53 | * Create new instance |
| 55 | 54 | * @param AuthorizationServerInterface $authorizationServer |
| 56 | 55 | */ |
| 57 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 58 | - {
|
|
| 56 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 59 | 57 | $this->authorizationServer = $authorizationServer; |
| 60 | 58 | } |
| 61 | 59 | |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | * @package Platine\Framework\OAuth2\Repository |
| 62 | 62 | * @extends Repository<OauthRefreshToken> |
| 63 | 63 | */ |
| 64 | -class RefreshTokenRepository extends Repository implements RefreshTokenRepositoryInterface |
|
| 65 | -{
|
|
| 64 | +class RefreshTokenRepository extends Repository implements RefreshTokenRepositoryInterface { |
|
| 66 | 65 | /** |
| 67 | 66 | * The Client Service |
| 68 | 67 | * @var ClientService |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | * @param EntityManager<OauthRefreshToken> $manager |
| 75 | 74 | * @param ClientService $clientService |
| 76 | 75 | */ |
| 77 | - public function __construct(EntityManager $manager, ClientService $clientService) |
|
| 78 | - {
|
|
| 76 | + public function __construct(EntityManager $manager, ClientService $clientService) { |
|
| 79 | 77 | parent::__construct($manager, OauthRefreshToken::class); |
| 80 | 78 | $this->clientService = $clientService; |
| 81 | 79 | } |
@@ -104,12 +102,12 @@ discard block |
||
| 104 | 102 | public function getByToken(string $token): ?BaseToken |
| 105 | 103 | {
|
| 106 | 104 | $refreshToken = $this->find($token); |
| 107 | - if ($refreshToken === null) {
|
|
| 105 | + if ($refreshToken === null) { |
|
| 108 | 106 | return null; |
| 109 | 107 | } |
| 110 | 108 | |
| 111 | 109 | $client = null; |
| 112 | - if ($refreshToken->client_id !== null) {
|
|
| 110 | + if ($refreshToken->client_id !== null) { |
|
| 113 | 111 | $client = $this->clientService->find($refreshToken->client_id); |
| 114 | 112 | } |
| 115 | 113 | |
@@ -136,12 +134,12 @@ discard block |
||
| 136 | 134 | public function saveRefreshToken(RefreshToken $token): RefreshToken |
| 137 | 135 | {
|
| 138 | 136 | $clientId = null; |
| 139 | - if ($token->getClient() !== null) {
|
|
| 137 | + if ($token->getClient() !== null) { |
|
| 140 | 138 | $clientId = $token->getClient()->getId(); |
| 141 | 139 | } |
| 142 | 140 | |
| 143 | 141 | $ownerId = null; |
| 144 | - if ($token->getOwner() !== null) {
|
|
| 142 | + if ($token->getOwner() !== null) { |
|
| 145 | 143 | $ownerId = $token->getOwner()->getOwnerId(); |
| 146 | 144 | } |
| 147 | 145 | |