2017-09-22 93 views
0

在狂饮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/onCompleteonError事件订户和文件需要升级的测试。

回答