Skip to content

Commit 0cd73a8

Browse files
wmouwenchalasr
authored andcommitted
Support Doctrine ORM 3.0
1 parent d365eba commit 0cd73a8

File tree

10 files changed

+48
-88
lines changed

10 files changed

+48
-88
lines changed

.github/workflows/static-analysis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ jobs:
1111
static-analysis:
1212
name: "static analysis"
1313
runs-on: "ubuntu-latest"
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
doctrine-orm: ['2.14.*', '2.18.*', '3.0.*']
18+
composer-flags: ['--prefer-stable']
19+
1420
steps:
1521
- name: "checkout"
1622
uses: "actions/checkout@v4"
1723

1824
- name: "build the environment"
1925
run: "dev/bin/docker-compose build"
2026

27+
- name: "require specific Doctrine ORM version"
28+
run: "dev/bin/php composer require --ansi ${{ matrix.composer-flags }} doctrine/orm:${{ matrix.doctrine-orm }}"
29+
2130
- name: "install dependencies"
22-
run: "dev/bin/php composer update --prefer-stable"
31+
run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}"
2332

2433
- name: "run static analysis"
2534
run: "dev/bin/php psalm --shepherd --stats"

.github/workflows/unit-tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ jobs:
1616
matrix:
1717
php: ['8.1', '8.2', '8.3']
1818
symfony: ['5.4.*', '6.4.*', '7.0.*']
19+
doctrine-orm: ['2.14.*', '2.18.*', '3.0.*']
1920
composer-flags: ['--prefer-stable']
2021
can-fail: [false]
2122
exclude:
2223
- php: "8.1"
2324
symfony: "7.0.*"
25+
- doctrine-orm: "2.14.*"
26+
symfony: "6.4.*"
27+
- doctrine-orm: "2.14.*"
28+
symfony: "7.0.*"
2429

25-
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
30+
name: "PHP ${{ matrix.php }} - Doctrine ${{ matrix.doctrine-orm }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
2631

2732
env:
2833
SYMFONY_REQUIRE: ${{ matrix.symfony }}
@@ -34,6 +39,9 @@ jobs:
3439
- name: "build the PHP environment"
3540
run: "dev/bin/docker-compose build --build-arg PHP_VERSION=${{ matrix.php }} --build-arg XDEBUG_VERSION='3.3.1' php"
3641

42+
- name: "require specific Doctrine ORM version"
43+
run: "dev/bin/php composer require --ansi ${{ matrix.composer-flags }} doctrine/orm:${{ matrix.doctrine-orm }}"
44+
3745
- name: "install dependencies"
3846
run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}"
3947

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^8.1",
2020
"doctrine/doctrine-bundle": "^2.0.8",
21-
"doctrine/orm": "^2.7.1",
21+
"doctrine/orm": "^2.14|^3.0",
2222
"league/oauth2-server": "^8.3",
2323
"nyholm/psr7": "^1.4",
2424
"psr/http-factory": "^1.0",

src/Model/AbstractClient.php

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,21 @@
1515
*/
1616
abstract class AbstractClient implements ClientInterface
1717
{
18-
/**
19-
* @var string
20-
*/
21-
private $name;
18+
private string $name;
19+
protected string $identifier;
20+
private ?string $secret;
2221

23-
/**
24-
* @var string
25-
*/
26-
protected $identifier;
22+
/** @var list<RedirectUri> */
23+
private array $redirectUris = [];
2724

28-
/**
29-
* @var string|null
30-
*/
31-
private $secret;
25+
/** @var list<Grant> */
26+
private array $grants = [];
3227

33-
/**
34-
* @var list<RedirectUri>
35-
*/
36-
private $redirectUris = [];
28+
/** @var list<Scope> */
29+
private array $scopes = [];
3730

38-
/**
39-
* @var list<Grant>
40-
*/
41-
private $grants = [];
42-
43-
/**
44-
* @var list<Scope>
45-
*/
46-
private $scopes = [];
47-
48-
/**
49-
* @var bool
50-
*/
51-
private $active = true;
52-
53-
/**
54-
* @var bool
55-
*/
56-
private $allowPlainTextPkce = false;
31+
private bool $active = true;
32+
private bool $allowPlainTextPkce = false;
5733

5834
/**
5935
* @psalm-mutation-free
@@ -165,7 +141,7 @@ public function setActive(bool $active): ClientInterface
165141
*/
166142
public function isConfidential(): bool
167143
{
168-
return !empty($this->secret);
144+
return null !== $this->secret && '' !== $this->secret;
169145
}
170146

171147
/**

src/Model/RefreshToken.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,15 @@
66

77
class RefreshToken implements RefreshTokenInterface
88
{
9-
/**
10-
* @var string
11-
*/
12-
private $identifier;
13-
14-
/**
15-
* @var \DateTimeInterface
16-
*/
17-
private $expiry;
18-
19-
/**
20-
* @var AccessTokenInterface|null
21-
*/
22-
private $accessToken;
23-
24-
/**
25-
* @var bool
26-
*/
27-
private $revoked = false;
9+
private string $identifier;
10+
private \DateTimeInterface $expiry;
11+
private ?AccessTokenInterface $accessToken;
12+
private bool $revoked = false;
2813

2914
/**
3015
* @psalm-mutation-free
3116
*/
32-
public function __construct(string $identifier, \DateTimeInterface $expiry, AccessTokenInterface $accessToken = null)
17+
public function __construct(string $identifier, \DateTimeInterface $expiry, ?AccessTokenInterface $accessToken = null)
3318
{
3419
$this->identifier = $identifier;
3520
$this->expiry = $expiry;

src/Security/Authenticator/OAuth2Authenticator.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,10 @@ final class OAuth2Authenticator implements AuthenticatorInterface, Authenticatio
3636
*/
3737
use ForwardCompatAuthenticatorTrait;
3838

39-
/**
40-
* @var HttpMessageFactoryInterface
41-
*/
42-
private $httpMessageFactory;
43-
44-
/**
45-
* @var ResourceServer
46-
*/
47-
private $resourceServer;
48-
49-
/**
50-
* @var UserProviderInterface
51-
*/
52-
private $userProvider;
53-
54-
/**
55-
* @var string
56-
*/
57-
private $rolePrefix;
39+
private HttpMessageFactoryInterface $httpMessageFactory;
40+
private ResourceServer $resourceServer;
41+
private UserProviderInterface $userProvider;
42+
private string $rolePrefix;
5843

5944
public function __construct(
6045
HttpMessageFactoryInterface $httpMessageFactory,
@@ -73,7 +58,7 @@ public function supports(Request $request): ?bool
7358
return str_starts_with($request->headers->get('Authorization', ''), 'Bearer ');
7459
}
7560

76-
public function start(Request $request, AuthenticationException $authException = null): Response
61+
public function start(Request $request, ?AuthenticationException $authException = null): Response
7762
{
7863
return new Response('', 401, ['WWW-Authenticate' => 'Bearer']);
7964
}

src/Security/Exception/InsufficientScopesException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class InsufficientScopesException extends OAuth2AuthenticationException
1111
{
12-
public static function create(\Throwable $previous = null): self
12+
public static function create(?\Throwable $previous = null): self
1313
{
1414
return new self('Insufficient scopes.', 403, $previous);
1515
}

src/Security/Exception/OAuth2AuthenticationException.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
*/
1313
class OAuth2AuthenticationException extends AuthenticationException implements HttpExceptionInterface
1414
{
15-
/**
16-
* @var int
17-
*/
18-
private $statusCode;
15+
private int $statusCode;
1916

20-
public function __construct(string $message, int $statusCode, \Throwable $previous = null)
17+
public function __construct(string $message, int $statusCode, ?\Throwable $previous = null)
2118
{
2219
$this->statusCode = $statusCode;
2320

src/Security/Exception/OAuth2AuthenticationFailedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class OAuth2AuthenticationFailedException extends OAuth2AuthenticationException
1111
{
12-
public static function create(string $message, \Throwable $previous = null): self
12+
public static function create(string $message, ?\Throwable $previous = null): self
1313
{
1414
return new self($message, 401, $previous);
1515
}

tests/Acceptance/DoctrineCredentialsRevokerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function buildRefreshToken(string $identifier, string $modify, AccessTok
9090
);
9191
}
9292

93-
private function buildAccessToken(string $identifier, string $modify, Client $client, string $userIdentifier = null): AccessToken
93+
private function buildAccessToken(string $identifier, string $modify, Client $client, ?string $userIdentifier = null): AccessToken
9494
{
9595
return new AccessToken(
9696
$identifier,
@@ -101,7 +101,7 @@ private function buildAccessToken(string $identifier, string $modify, Client $cl
101101
);
102102
}
103103

104-
private function buildAuthCode(string $identifier, string $modify, Client $client, string $userIdentifier = null): AuthorizationCode
104+
private function buildAuthCode(string $identifier, string $modify, Client $client, ?string $userIdentifier = null): AuthorizationCode
105105
{
106106
return new AuthorizationCode(
107107
$identifier,

0 commit comments

Comments
 (0)