Skip to content

Commit 6379ef5

Browse files
committed
bug #46 SuperClass AbstractClient can not have indentifier mapped (yoshz)
This PR was merged into the 0.1-dev branch. Discussion ---------- SuperClass AbstractClient can not have indentifier mapped This is a fix for bug #45. Turns out that AbstractClient is wrongly mapped. Quoted from [Doctrine/ORM documentation](master...yoshz:bugfix/docrine-mapping): > A mapped superclass cannot be an entity, it is not query-able and persistent relationships defined by a mapped superclass must be unidirectional (with an owning side only). This means that One-To-Many associations are not possible on a mapped superclass at all. Furthermore Many-To-Many associations are only possible if the mapped superclass is only used in exactly one entity at the moment. For further support of inheritance, the single or joined table inheritance features have to be used. So AbstractClient can not have an identifier and can not be used as an association between entities. Commits ------- b91268b SuperClass AbstractClient can not have indentifier mapped
2 parents 50633c1 + b91268b commit 6379ef5

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

docs/using-custom-client.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Doctrine\ORM\Mapping as ORM;
1515
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
1616

17-
/**
18-
* @ORM\Entity
19-
*/
17+
#[ORM\Entity]
2018
class Client extends AbstractClient
2119
{
22-
/**
23-
* @ORM\Column(type="string")
24-
*/
20+
#[ORM\Id]
21+
#[ORM\Column(type: 'string', length: 32)]
22+
protected $identifier;
23+
24+
#[ORM\Column(type: 'string')]
2525
private $image;
2626

2727
// other properties, getters, setters, ...

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection;
66

7-
use Defuse\Crypto\Key;
87
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
98
use League\Bundle\OAuth2ServerBundle\AuthorizationServer\GrantTypeInterface;
109
use League\Bundle\OAuth2ServerBundle\Command\CreateClientCommand;
@@ -16,7 +15,6 @@
1615
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager;
1716
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\RefreshTokenManager;
1817
use League\Bundle\OAuth2ServerBundle\Manager\ScopeManagerInterface;
19-
use League\Bundle\OAuth2ServerBundle\Model\Client;
2018
use League\Bundle\OAuth2ServerBundle\Model\Scope as ScopeModel;
2119
use League\Bundle\OAuth2ServerBundle\Persistence\Mapping\Driver;
2220
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
@@ -268,7 +266,7 @@ private function configureDoctrinePersistence(ContainerBuilder $container, array
268266

269267
$container
270268
->findDefinition(Driver::class)
271-
->replaceArgument(0, Client::class !== $config['client']['classname'])
269+
->replaceArgument(0, $config['client']['classname'])
272270
;
273271

274272
$container->setParameter('league.oauth2_server.persistence.doctrine.enabled', true);

src/Model/AbstractClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class AbstractClient
1919
/**
2020
* @var string
2121
*/
22-
private $identifier;
22+
protected $identifier;
2323

2424
/**
2525
* @var string|null

src/Persistence/Mapping/Driver.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
class Driver implements MappingDriver
2222
{
2323
/**
24-
* @var bool
24+
* @var string
2525
*/
26-
private $withCustomClientClass;
26+
private $clientClass;
2727

28-
public function __construct(bool $withCustomClientClass)
28+
public function __construct(string $clientClass)
2929
{
30-
$this->withCustomClientClass = $withCustomClientClass;
30+
$this->clientClass = $clientClass;
3131
}
3232

3333
public function loadMetadataForClass($className, ClassMetadata $metadata): void
@@ -67,20 +67,19 @@ public function getAllClassNames(): array
6767
AuthorizationCode::class,
6868
RefreshToken::class,
6969
],
70-
$this->withCustomClientClass ? [] : [Client::class]
70+
Client::class === $this->clientClass ? [Client::class] : []
7171
);
7272
}
7373

7474
public function isTransient($className): bool
7575
{
76-
return AbstractClient::class !== $className;
76+
return false;
7777
}
7878

7979
private function buildAbstractClientMetadata(ClassMetadata $metadata): void
8080
{
8181
(new ClassMetadataBuilder($metadata))
8282
->setMappedSuperClass()
83-
->createField('identifier', 'string')->makePrimaryKey()->length(32)->build()
8483
->createField('name', 'string')->length(128)->build()
8584
->createField('secret', 'string')->length(128)->nullable(true)->build()
8685
->createField('redirectUris', 'oauth2_redirect_uri')->nullable(true)->build()
@@ -100,7 +99,7 @@ private function buildAccessTokenMetadata(ClassMetadata $metadata): void
10099
->createField('userIdentifier', 'string')->length(128)->nullable(true)->build()
101100
->createField('scopes', 'oauth2_scope')->nullable(true)->build()
102101
->addField('revoked', 'boolean')
103-
->createManyToOne('client', Client::class)->addJoinColumn('client', 'identifier', false, false, 'CASCADE')->build()
102+
->createManyToOne('client', $this->clientClass)->addJoinColumn('client', 'identifier', false, false, 'CASCADE')->build()
104103
;
105104
}
106105

@@ -113,13 +112,16 @@ private function buildAuthorizationCodeMetadata(ClassMetadata $metadata): void
113112
->createField('userIdentifier', 'string')->length(128)->nullable(true)->build()
114113
->createField('scopes', 'oauth2_scope')->nullable(true)->build()
115114
->addField('revoked', 'boolean')
116-
->createManyToOne('client', Client::class)->addJoinColumn('client', 'identifier', false, false, 'CASCADE')->build()
115+
->createManyToOne('client', $this->clientClass)->addJoinColumn('client', 'identifier', false, false, 'CASCADE')->build()
117116
;
118117
}
119118

120119
private function buildClientMetadata(ClassMetadata $metadata): void
121120
{
122-
(new ClassMetadataBuilder($metadata))->setTable('oauth2_client');
121+
(new ClassMetadataBuilder($metadata))
122+
->setTable('oauth2_client')
123+
->createField('identifier', 'string')->makePrimaryKey()->length(32)->build()
124+
;
123125
}
124126

125127
private function buildRefreshTokenMetadata(ClassMetadata $metadata): void

0 commit comments

Comments
 (0)