【发布时间】:2019-10-19 15:16:55
【问题描述】:
我正在使用 symfony4。我关注 this tutorial 创建自定义捆绑包。一切正常。 从现在开始,我想在我的包中使用 KernelInterface。如何在我的包中添加一些服务(如内核)?
我尝试在我的 bundle services.yml 中添加内核
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="lilworks.youtubedl" class="Lilworks\YoutubeDlBundle\LilworksYoutubeDl" public="true">
<argument type="service" id="kernel" />
</service>
<service id="Lilworks\YoutubeDlBundle\LilworksYoutubeDl" alias="lilworks.youtubedl" public="true"/>
</services>
<?php
namespace Lilworks\YoutubeDlBundle;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
class LilworksYoutubeDl
{
private $foo;
private $bar;
private $kernel;
public function __construct($foo,$bar,KernelInterface $kernelInterface)
{
$this->foo = $foo;
$this->bar = $bar;
$this->kernel = $kernelInterface;
}
}
【问题讨论】:
-
所以不要让我们悬而未决:发生了什么事?关于 $foo 和 $bar 的错误?绝对没有?其他一些错误?对于捆绑包,服务是手动配置的,因此您走在正确的轨道上。和题外话,但你实际上不太可能需要访问内核。
-
你需要内核做什么? XML 是如何进入
services.yml的?
标签: symfony