[Li Jingshan php] every day laravel-20160908| Dispatcher-8

Source: Internet
Author: User

    /**     * 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

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.