/**
* Sort the listeners for a given event by priority.
*
* @param string $eventName
* @return array
*/
protected function sortListeners($eventName)
{
$this->sorted[$eventName] = [];// use sort listener
// If listeners exist for the given event, we will sort them by the priority
// so that we can call them in the correct order. We will cache off these
// sorted event listeners so we do not have to re-sort on every events.
if (isset($this->listeners[$eventName])) {// check it is set
krsort($this->listeners[$eventName]);// krsort is a sort method
$this->sorted[$eventName] = call_user_func_array(
'array_merge', $this->listeners[$eventName]
);// call user func array
// very good use type
}// priority is a first thing
}
/**
* Register an event listener with the dispatcher.
*
* @param mixed $listener
* @return mixed
*/
public function makeListener($listener)
{
return is_string($listener) ? $this->createClassListener($listener) : $listener;
}// Register an event listener with the dispatcher.
// if it is a string create ClassListener use this method
/**
* Create a class based listener using the IoC container.
*
* @param mixed $listener
* @return \Closure
*/
public function createClassListener($listener)// create Class Listener
{
$container = $this->container;// use this container
return function () use ($listener, $container) {
return call_user_func_array(
$this->createClassCallable($listener, $container), func_get_args()
);
};// a use function
}
[李景山php]每天laravel-20160907|Dispatcher-7
最新推荐文章于 2024-10-18 14:55:22 发布