我正在尝试根据此处给出的示例设置一个简单的事件订阅 - http://symfony.com/doc/master/components/event_dispatcher/introduction.html.
这是我的活动商店:
namespace CookBook\InheritanceBundle\Event;
final class EventStore
{
const EVENT_SAMPLE = 'event.sample';
}
Run Code Online (Sandbox Code Playgroud)
这是我的活动订阅者:
namespace CookBook\InheritanceBundle\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
class Subscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
var_dump('here');
return array(
'event.sample' => array(
array('sampleMethod1', 10),
array('sampleMethod2', 5)
));
}
public function sampleMethod1(Event $event)
{
var_dump('Method 1');
}
public function sampleMethod2(Event $event)
{
var_dump('Method 2');
}
}
Run Code Online (Sandbox Code Playgroud)
这是services.yml中的配置:
kernel.subscriber.subscriber:
class: CookBook\InheritanceBundle\Event\Subscriber
tags:
- {name:kernel.event_subscriber}
Run Code Online (Sandbox Code Playgroud)
以下是我举办活动的方式:
use Symfony\Component\EventDispatcher\EventDispatcher;
use CookBook\InheritanceBundle\Event\EventStore;
$dispatcher = new EventDispatcher();
$dispatcher->dispatch(EventStore::EVENT_SAMPLE);
Run Code Online (Sandbox Code Playgroud)
预期产量: …
我试图将关联数组作为参数传递给服务定义(确切地说是日光浴).但是,我收到以下错误:
"可捕获的致命错误:传递给Symfony\Component\DependencyInjection\Definition :: setArguments()的参数1必须是数组类型,字符串给定,"
我的services.yml内容如下:
parameters:
mynamespace.api.solrclient.config:
endpoint:
solrserver:
host: "search.mysite.com"
port: "80"
path: "/solr/"
services:
mynamespace.api.solrclient:
class: Solarium\Client
arguments: "%mynamespace.api.solrclient.config%"
Run Code Online (Sandbox Code Playgroud)
我定义参数数组的方式有什么明显错误吗?