在 sf4 包中定义服务参数

Define services parameters inside a sf4 bundle

我正在尝试在捆绑包中配置服务。此服务需要 the.env 文件中的一些参数,但我无法在服务中声明这些参数。这是我的代码:

src/Dfc2/WsBundle/Services/WsManager/WsManager.yaml

parameters:
    wsAdminUser: '%env(WSADMIN_USER)%'
    wsAdminPassword: '%env(WSADMIN_PASSWORD)%'
services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    WsManager:
        public: true
        class: App\Dfc2\WsBundle\Services\WsManager\WsManager
        arguments:
            $env: '%kernel.environment%'
            $wsAdminUser: '%wsAdminUser%'
            $wsAdminPassword: '%wsAdminPassword%'

src/Dfc2/WsBundle/Services/WsManager/WsManager.php 构造函数:

public function __construct($env, RequestStack $requestStack, SessionInterface $session, string $wsAdminUser, string $wsAdminPassword)
{

    $this->environement = $env;
    $this->wsAdminUser = $wsAdminUser;
    $this->wsAdminPassword = $wsAdminPassword;
    $this->session = $session;
    $this->baseUrl = $requestStack->getCurrentRequest()->getBaseUrl() . WsParameters::URL_SUFFIX;
    $this->setBaseUrl();

}

这是我收到的错误消息。

Cannot autowire service "App\Dfc2\WsBundle\Services\WsManager\WsManager": argument "$wsAdminUser" of method "__construct()" must have a type-hint or be given a value explicitly.

我不明白怎么了。你能帮帮我吗?

感谢 Mathieu Dormeval 和 Cerad, 我像这样更改了我的服务定义,现在它可以工作了:

services:
    App\Dfc2\WsBundle\Services\WsManager\WsManager:
        autowire: false
        public: true
        arguments:
            $env: '%kernel.environment%'
            $requestStack: '@request_stack'
            $session: '@session'
            $wsAdminUser: '%wsAdminUser%'
            $wsAdminPassword: '%wsAdminPassword%'