Guzzle 6中的GuzzleHttp \ Event \ SubscriberInterface相当于什么?
问题描述:
在狂饮5.3,你可以在下面的例子中使用event subscribers为:Guzzle 6中的GuzzleHttp Event SubscriberInterface相当于什么?
use GuzzleHttp\Event\EmitterInterface;
use GuzzleHttp\Event\SubscriberInterface;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Event\CompleteEvent;
class SimpleSubscriber implements SubscriberInterface
{
public function getEvents()
{
return [
// Provide name and optional priority
'before' => ['onBefore', 100],
'complete' => ['onComplete'],
// You can pass a list of listeners with different priorities
'error' => [['beforeError', 'first'], ['afterError', 'last']]
];
}
public function onBefore(BeforeEvent $event, $name)
{
echo 'Before!';
}
public function onComplete(CompleteEvent $event, $name)
{
echo 'Complete!';
}
}
什么是在狂饮6等价的例子吗?
因为我phpunit
正在使用onBefore
/onComplete
和onError
事件订户和文件需要升级的测试。
答
下面是示例代码这相当于onBefore
事件:
use Psr\Http\Message\RequestInterface;
class SimpleSubscriber {
public function __invoke(RequestInterface $request, array $options)
{
echo 'Before!';
}
}
来源:systemhaus/GuzzleHttpMock
的7efe898
commit叉aerisweather/GuzzleHttpMock
。