command是运行在控制台中;如果想要生成绝对URL;由于在控制台中无法获取请求上下文;所以需要配置请求上下文
####全局配置
# app/config/parameters.yml
parameters:
router.request_context.host: example.org
router.request_context.scheme: https
router.request_context.base_url: my/path
####在各个命令中设置
$context = $this->getContainer()->get('router')->getContext();
$context->setHost('example.com');
$context->setScheme('https');
$context->setBaseUrl('/my/path');
//eg: ttps://example.com/my/path/test/command 最终生成的URL
$this->getContainer()->get('router')->generate("test_command", [], true);