我目前正在尝试在symfony 3.3项目中设置phpleague/oauth-server
。出于这个原因,我想指定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/
How to configure dependency injection for repository class in symfony 3
他们都没有工作。有没有人知道为什么我的存储库的服务定义不被接受为AuthorizationServer
的有效输入?
此致, FMK
答案 0 :(得分:0)
我曾尝试扩展EntityRepository但忘记在实体中定义存储库。随着存储库扩展实体中的entityRepository和ORM \ Entity定义,它似乎工作!