/** * Create the class based event callable. * * @param string $listener * @param \illuminate\container\ container $container * @return callable */ protected function createclasscallable ($listener, $ Container) {// create the class based event callable. list ($class, $method) = $this Parseclasscallable ($listener);// set this parameters like class and method/ / i like this way more , if ($this->handlershouldbequeued ($class)) {// if true return $this- >createqueuedhandlercallable ($class, $method);// use a wrap class } else { return [$container->make ($class), $method];// a make and a method } } /** * Parse the class listener into class and method. * * @param string $listener * @return array */ protected function parseclasscallable ($listener) { $segments = explode (' @ ', $listener);// if has @ use it , return [$segments [0], count ($ Segments) == 2 ? $segments [1] : ' handle '];// else return it }//parse Class Call able /** * determine if the event handler class should be queued. * * @param string $class * @return bool */ Protected function handlershouldbequeued ($class) {// handler shouldbequeued try { return (New reflectionclass ($class))->implementsinterface ( ' Illuminate\contracts\queue\shouldqueue ' );// get the reflection Class } catch (exception $e) { return false; } } /** * Create a callable for putting an event handler on the queue. * * @param string $class * @param string $method * @return &Nbsp;\closure */ protected function Createqueuedhandlercallable ($class, $method) {// create a callable for putting an event handler on the queue. return function () use ($class, $method) { $arguments = $this Cloneargumentsforqueueing (Func_get_args ());// get the arguments// get the arguments, get all arguments like a array // prepare this argument if (method_exists ($class, ' queue ')) {// check has method $this->callqueuemethodonhandler ($class, $method, $arguments);// call queuemethodonhandler } else { $this->resolvequeue ()->push (' illuminate\events\[email protected] ', [ ' class ' => $class, ' method ' => $method, ' data ' => Serialize ($arguments), ]); }// other set something wrong }; } /** * Clone the given arguments for queueing. * * @param array $arguments * @return array */ Protected function cloneargumentsforqueueing (array $arguments) { return array_map (function ($a) { return is_object ($a) ? clone $a : $a; }, $arguments);// just a array_map }// done every thing just a good way // too beautiful /** * call the queue method on the handler class. * * @ param string $class * @param string $method * @param array $arguments * @return void */ protected function callqueuemethodonhandler ($class, $method, $arguments) { $handler = (New reflectionclass ($class)) Newinstancewithoutconstructor ();// a handler method $handler->queue ($this->resolvequeue (), ' illuminate\events\[email protected] ', [ ' class ' => $class, ' Method ' => $method, ' data ' => serialize ($arguments), ]);// set the handler }//Call the queue method on the handler class /** * remove a set of listeners from the dispatcher. * * @param string $event * @ Return void */ public function forget ($ Event) { if (Str::contains ($event, ' * ') { unset ($this) wildcards[$event]);// unset all } else { &nbSp; unset ($this->listeners[$event], $this->sorted[$event]);// unset this point just you want } }// forget , like remove a set of listeners From the dispatcher /** * forget all of the pushed listeners. * * @return void */ public function Forgetpushed () { foreach ($this- >listeners as $key => $value) { if (Str::endswith ($key, ' _pushed ')) { $this->forget ($key); } } }// forget Pushed /** * Get the queue implementation from the resolver. * * @return \Illuminate\Contracts\Queue\Queue */ Protected function resolvequeue () { return call_user_func ($this->queueresolver);// just a magic call }//resolve queue /** * set the queue resolver implementation. * * @param callable $resolver * @return $this */ public function setqueueresolver (callable $resolver) { $this->queueresolver = $ resolver; return $this; }// Return self is better}
This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1793128
[Li Jingshan php] every day laravel-20160908| Dispatcher-8