我在Symfony 3.3的服务中使用了一个参数,但我一直收到错误.
错误
[Symfony\Component\DependencyInjection\Exception\AutowiringFailedException]无法自动装配服务"AppBundle\Service\ApiInterface":方法"__construct()"的参数"$ api_endpoint"必须具有类型提示或显式赋予值.
config.yml
services:
app.security.login_form_authenticator:
class: AppBundle\Security\LoginFormAuthenticator
autowire: true
arguments: ['@doctrine.orm.entity_manager']
app.service.api_interface:
class: AppBundle\Service\ApiInterface
arguments:
$api_endpoint: "%endpoint test%"
_defaults:
autowire: true
autoconfigure: true
public: false
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
Run Code Online (Sandbox Code Playgroud)
ApiInterface.php
use Unirest;
class ApiInterface
{
private $api_endpoint;
public function __construct(string $api_endpoint)
{
$this->timeout = 1;
echo 'form apiinterface construct: ' . $api_endpoint;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示感觉我会围成一圈,这应该是一个简单的工作!