对于我正在开发的一个项目,使用我很陌生的 Symfony,我试图创建一个使用依赖注入但也需要一些自定义参数的类的对象。
现在假设我有一个命令:
<?php
class ServerCommand extends Command {
public function __construct(Server $server) {
$this->server = $server;
}
protected function execute(InputInterface $input, OutputInterface $output) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个服务器类:
<?php
class Server {
public function __construct(MessageManager $messageManager, InputInterface $input, OutputInterface $output) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
现在,Server类被注入到Command类中,MessageManager类被注入到Server类中。
我遇到的问题是将类中的$input和$ouput变量Command放入服务器类的构造函数中。
为了使它变得更加困难,我还希望在类中可以访问$input和变量。$outputMessageManager
这可能吗?如果可以,我该如何实现这一目标?
symfony ×1