[Li Jingshan php] every day laravel-20160905| Dispatcher-5

Source: Internet
Author: User

    /**     * fire an event and call  the listeners.     *     *  @param    string|object   $event      *  @param   mixed  $ payload     *  @param   bool   $halt       *  @return  array|null     */   //     public function fire ($event,  $payload  = [],  $halt  = false)      {// fire means to start       //  call listeners        // when the given   "Event"  is actually an object we will assume[like] it is  an event   &nBsp;    // object and use the class as the event  name and this event itself as the         // payload to the handler, which makes object based  events quite simple.        if  (Is_object ($event))  {// determine is a object             list ($payload,  $event)  = [[$event], get_class ($event)];         }// set this as list function        // now i love this function          $responses  = [];// prepare listener         // if an array is not given to us as the payload, we will turn  It into one so        // we can easily  use call_user_func_array on the listeners, passing in the         // payload to each of them so that  they receive each of these arguments.         if  (! is_array ($payload))  {              $payload  = [$payload];// be array         }// if it is a array         $this firing[] =  $event;// set this firing listener         if  (iSset ($payload [0])  &&  $payload [0] instanceof shouldbroadcast]  {              $this->broadcastevent ($payload [0]);         }        foreach  ($this Getlisteners ($event)  as  $listener)  {            // use a function to return big array and list  loop it             $response  = call _user_func_array ($listener,  $payload);// cal_user_func_array// get response             // If a response is  returned from the listener and event halting is enabled        &Nbsp;    // we will just return this response, and  not call the rest of the event             // listeners. Otherwise we will add the  response on the response list.             if  (! is_null ($response)  &&  $halt)  {                 array_pop ($this->firing);// if  null array_pop it                 return  $response;// return it             }// add response on the response list        &nbSp;    // if a boolean false is returned from a  listener, we will stop propagating             // the event to any further listeners down in  the chain, else we keep on             // looping through the listeners and firing every  one in our sequence.             if  ($response  === false)  {                 break;             }// if response is null              $responses []&NBsp;=  $response;// otherwise        }         array_pop ($this->firing);// pop it         return  $halt  ? null :  $responses;     }


This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1791598

[Li Jingshan php] every day laravel-20160905| Dispatcher-5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.