2014-01-21 1 views
0

는이 전과 같이 Laravel에 두 개의 리스너 있다고 가정 해 봅시다 : 나는 기본적으로 리스너의 우선 순위를 0으로 설정 알고하지만 위의 두 사이에 이벤트를 추가하는 것을 원하는 경우Laravel 리스너 우선 순위

Event::listen('eventOne', 'myListenerOne'); 
Event::listen('eventThree', 'myListenerThree'); 

?

Event::listen('eventTwo', 'myListenerTwo'); 

우선 순위는 무엇입니까?

답변

0

Laravel < = 5.3

그냥 여기

Event::listen('eventTwo', 'myListenerTwo', 1); 

하나 더 이벤트 우선 순위를 이해하는 작은 예라고, 더 큰 우선 순위로 리스너를 추가

Event::listen(
    'test', function() { 
      echo 'On test, first added but last executed', PHP_EOL; 
     }, -1); 


Event::listen(
    'test', function() { 
      echo 'On test, added in the middle and executed in the middle', PHP_EOL; 
     }); 


Event::listen(
    'test', function() { 
      echo 'On test, last added but first executed', PHP_EOL; 
     }, 1); 

Event::fire('test'); 

PS :

당신은 laravel 소스를 들여다 보며 언제든지 Illuminate\Events\Dispatcher::sortListeners으로 자신을 확인할 수 있습니다.

P.P.S :

이벤트 우선 순위 has been removed in Laravel 5.4