我目前正试图在symfony 3.3项目中设置phpleague/oauth-server
。出于这个原因,我想将AuthorizationServer
指定为服务,以便能够从容器中加载它(而不是在使用它的任何地方设置整个东西)。
要将AuthorizationServer
设置为服务,我需要注入多个存储库作为参数。
这是AuthorizationServer
:的服务定义
app.oauth2.authorization_server:
class: LeagueOAuth2ServerAuthorizationServer
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: AppbundleRepositoryOAuth2ClientRepository
factory: 'doctrine.orm.entity_manager:getRepository'
arguments: [AppBundleEntityOAuth2Client]
...
我尝试了很多方法将存储库定义为服务,但每次我都会遇到同样的错误:
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 AppBundleRepositoryOAuth2;
use LeagueOAuth2ServerEntitiesClientEntityInterface;
use LeagueOAuth2ServerRepositoriesClientRepositoryInterface;
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
的有效输入吗?
您的,FMK-
我曾试图扩展EntityRepository,但忘记在实体中定义存储库。随着存储库扩展entityRepository和实体中的ORM\Entity定义,它似乎可以工作!