Skip to content

Commit

Permalink
Merge pull request #86 from Nyholm/converter-interface
Browse files Browse the repository at this point in the history
Added interfaces for converters
  • Loading branch information
spideyfusion authored Aug 17, 2019
2 parents 9dce66a + 9b40f2a commit d2caf69
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Controller/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\UserConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\UserConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Event\AuthorizationRequestResolveEvent;
use Trikoder\Bundle\OAuth2Bundle\Event\AuthorizationRequestResolveEventFactory;
use Trikoder\Bundle\OAuth2Bundle\OAuth2Events;
Expand All @@ -33,15 +33,15 @@ final class AuthorizationController
private $eventFactory;

/**
* @var UserConverter
* @var UserConverterInterface
*/
private $userConverter;

public function __construct(
AuthorizationServer $server,
EventDispatcherInterface $eventDispatcher,
AuthorizationRequestResolveEventFactory $eventFactory,
UserConverter $userConverter
UserConverterInterface $userConverter
) {
$this->server = $server;
$this->eventDispatcher = $eventDispatcher;
Expand Down
10 changes: 3 additions & 7 deletions Converter/ScopeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
use Trikoder\Bundle\OAuth2Bundle\League\Entity\Scope as ScopeEntity;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope as ScopeModel;

final class ScopeConverter
final class ScopeConverter implements ScopeConverterInterface
{
public function toDomain(ScopeEntity $scope): ScopeModel
{
return new ScopeModel($scope->getIdentifier());
}

/**
* @param ScopeEntity[] $scopes
*
* @return ScopeModel[]
* {@inheritdoc}
*/
public function toDomainArray(array $scopes): array
{
Expand All @@ -35,9 +33,7 @@ public function toLeague(ScopeModel $scope): ScopeEntity
}

/**
* @param ScopeModel[] $scopes
*
* @return ScopeEntity[]
* {@inheritdoc}
*/
public function toLeagueArray(array $scopes): array
{
Expand Down
29 changes: 29 additions & 0 deletions Converter/ScopeConverterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Trikoder\Bundle\OAuth2Bundle\Converter;

use Trikoder\Bundle\OAuth2Bundle\League\Entity\Scope as ScopeEntity;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope as ScopeModel;

interface ScopeConverterInterface
{
public function toDomain(ScopeEntity $scope): ScopeModel;

/**
* @param ScopeEntity[] $scopes
*
* @return ScopeModel[]
*/
public function toDomainArray(array $scopes): array;

public function toLeague(ScopeModel $scope): ScopeEntity;

/**
* @param ScopeModel[] $scopes
*
* @return ScopeEntity[]
*/
public function toLeagueArray(array $scopes): array;
}
2 changes: 1 addition & 1 deletion Converter/UserConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Security\Core\User\UserInterface;
use Trikoder\Bundle\OAuth2Bundle\League\Entity\User;

final class UserConverter
final class UserConverter implements UserConverterInterface
{
public function toLeague(?UserInterface $user): UserEntityInterface
{
Expand Down
13 changes: 13 additions & 0 deletions Converter/UserConverterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Trikoder\Bundle\OAuth2Bundle\Converter;

use League\OAuth2\Server\Entities\UserEntityInterface;
use Symfony\Component\Security\Core\User\UserInterface;

interface UserConverterInterface
{
public function toLeague(?UserInterface $user): UserEntityInterface;
}
6 changes: 3 additions & 3 deletions Event/AuthorizationRequestResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use RuntimeException;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Security\Core\User\UserInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Model\Client;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope;
Expand All @@ -26,7 +26,7 @@ final class AuthorizationRequestResolveEvent extends Event
private $authorizationRequest;

/**
* @var ScopeConverter
* @var ScopeConverterInterface
*/
private $scopeConverter;

Expand All @@ -50,7 +50,7 @@ final class AuthorizationRequestResolveEvent extends Event
*/
private $user;

public function __construct(AuthorizationRequest $authorizationRequest, ScopeConverter $scopeConverter, ClientManagerInterface $clientManager)
public function __construct(AuthorizationRequest $authorizationRequest, ScopeConverterInterface $scopeConverter, ClientManagerInterface $clientManager)
{
$this->authorizationRequest = $authorizationRequest;
$this->scopeConverter = $scopeConverter;
Expand Down
6 changes: 3 additions & 3 deletions Event/AuthorizationRequestResolveEventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Trikoder\Bundle\OAuth2Bundle\Event;

use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;

class AuthorizationRequestResolveEventFactory
{
/**
* @var ScopeConverter
* @var ScopeConverterInterface
*/
private $scopeConverter;

Expand All @@ -20,7 +20,7 @@ class AuthorizationRequestResolveEventFactory
*/
private $clientManager;

public function __construct(ScopeConverter $scopeConverter, ClientManagerInterface $clientManager)
public function __construct(ScopeConverterInterface $scopeConverter, ClientManagerInterface $clientManager)
{
$this->scopeConverter = $scopeConverter;
$this->clientManager = $clientManager;
Expand Down
6 changes: 3 additions & 3 deletions League/Repository/AccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\League\Entity\AccessToken as AccessTokenEntity;
use Trikoder\Bundle\OAuth2Bundle\Manager\AccessTokenManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
Expand All @@ -27,14 +27,14 @@ final class AccessTokenRepository implements AccessTokenRepositoryInterface
private $clientManager;

/**
* @var ScopeConverter
* @var ScopeConverterInterface
*/
private $scopeConverter;

public function __construct(
AccessTokenManagerInterface $accessTokenManager,
ClientManagerInterface $clientManager,
ScopeConverter $scopeConverter
ScopeConverterInterface $scopeConverter
) {
$this->accessTokenManager = $accessTokenManager;
$this->clientManager = $clientManager;
Expand Down
6 changes: 3 additions & 3 deletions League/Repository/AuthCodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\League\Entity\AuthCode;
use Trikoder\Bundle\OAuth2Bundle\Manager\AuthorizationCodeManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
Expand All @@ -26,14 +26,14 @@ final class AuthCodeRepository implements AuthCodeRepositoryInterface
private $clientManager;

/**
* @var ScopeConverter
* @var ScopeConverterInterface
*/
private $scopeConverter;

public function __construct(
AuthorizationCodeManagerInterface $authorizationCodeManager,
ClientManagerInterface $clientManager,
ScopeConverter $scopeConverter
ScopeConverterInterface $scopeConverter
) {
$this->authorizationCodeManager = $authorizationCodeManager;
$this->clientManager = $clientManager;
Expand Down
6 changes: 3 additions & 3 deletions League/Repository/ScopeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Event\ScopeResolveEvent;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ScopeManagerInterface;
Expand All @@ -30,7 +30,7 @@ final class ScopeRepository implements ScopeRepositoryInterface
private $clientManager;

/**
* @var ScopeConverter
* @var ScopeConverterInterface
*/
private $scopeConverter;

Expand All @@ -42,7 +42,7 @@ final class ScopeRepository implements ScopeRepositoryInterface
public function __construct(
ScopeManagerInterface $scopeManager,
ClientManagerInterface $clientManager,
ScopeConverter $scopeConverter,
ScopeConverterInterface $scopeConverter,
EventDispatcherInterface $eventDispatcher
) {
$this->scopeManager = $scopeManager;
Expand Down
11 changes: 7 additions & 4 deletions League/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\UserConverter;
use Trikoder\Bundle\OAuth2Bundle\Converter\UserConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Event\UserResolveEvent;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Model\Grant as GrantModel;
Expand All @@ -26,12 +26,15 @@ final class UserRepository implements UserRepositoryInterface
private $eventDispatcher;

/**
* @var UserConverter
* @var UserConverterInterface
*/
private $userConverter;

public function __construct(ClientManagerInterface $clientManager, EventDispatcherInterface $eventDispatcher, UserConverter $userConverter)
{
public function __construct(
ClientManagerInterface $clientManager,
EventDispatcherInterface $eventDispatcher,
UserConverterInterface $userConverter
) {
$this->clientManager = $clientManager;
$this->eventDispatcher = $eventDispatcher;
$this->userConverter = $userConverter;
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@
<!-- Utility services -->
<service id="Trikoder\Bundle\OAuth2Bundle\Converter\UserConverter" />
<service id="trikoder.oauth2.converter.user_converter" alias="Trikoder\Bundle\OAuth2Bundle\Converter\UserConverter" />
<service id="Trikoder\Bundle\OAuth2Bundle\Converter\UserConverterInterface" alias="Trikoder\Bundle\OAuth2Bundle\Converter\UserConverter" />

<service id="Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter" />
<service id="trikoder.oauth2.converter.scope_converter" alias="Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter" />
<service id="Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface" alias="Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter" />

<service id="Trikoder\Bundle\OAuth2Bundle\Event\AuthorizationRequestResolveEventFactory">
<argument type="service" id="Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter" />
Expand Down

0 comments on commit d2caf69

Please sign in to comment.