Вставить репозиторий в phpleague/oauth-сервер:authServer
В настоящее время я пытаюсь настроить phpleague/oauth-server
в проекте Symfony 3.3. По этой причине я хочу указать AuthorizationServer
в качестве службы, чтобы иметь возможность загрузить его из контейнера (а не настроить всю вещь везде, где он используется).
Чтобы установить AuthorizationServer
в качестве службы мне нужно ввести несколько репозиториев в качестве аргументов.
Это определение сервиса для AuthorizationServer
:
app.oauth2.authorization_server:
class: League\OAuth2\Server\AuthorizationServer
arguments: ["@app.oauth2.client_repository", "@app.oauth2.access_token_repository", "@app.oauth2.scope_repository", "%oauth_private_key%", "%oauth_encryption_key%"]
configurator: "app.oauth2.authorization_server.configurator:configure"
Текущее определение репозиториев выглядит так:
app.oauth2.client_repository:
class: Appbundle\Repository\OAuth2\ClientRepository
factory: 'doctrine.orm.entity_manager:getRepository'
arguments: [AppBundle\Entity\OAuth2\Client]
...
Я пробовал много способов определить репозитории как сервисы, но каждый раз я получаю одну и ту же ошибку:
Type error: Argument 1 passed to League\\OAuth2\\Server\\AuthorizationServer::__construct() must be an instance of League\\OAuth2\\Server\\Repositories\\ClientRepositoryInterface, instance of Doctrine\\ORM\\EntityRepository given
Вот как выглядит ClientRepository:
<?php
namespace AppBundle\Repository\OAuth2;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class ClientRepository implements ClientRepositoryInterface
{
/**
* Get a client.
*
* @param string $clientIdentifier The client's identifier
* @param string $grantType The grant type used
* @param null|string $clientSecret The client's secret (if sent)
* @param bool $mustValidateSecret If true the client must attempt to validate the secret if the client
* is confidential
*
* @return ClientEntityInterface
*/
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
{
// TODO: Implement getClientEntity() method.
}
}
Вот несколько других способов, которыми я пытался это реализовать:
https://matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/
Как настроить внедрение зависимостей для класса репозитория в Symfony 3
Ни один из них не работал. Есть ли у кого-нибудь из вас представление, почему определение сервиса моего репозитория не принимается как действительный вход для AuthorizationServer
?
Ваш, ФМК
1 ответ
Я пытался расширить EntityRepository, но забыл определить хранилище в Entities. С репозиториями, расширяющими entityRepository и определение ORM\Entity в Entities, это, кажется, работает!