Home > Backend Development > PHP Tutorial > [Li Jingshan php]daily laravel-20160906|Dispatcher-6

[Li Jingshan php]daily laravel-20160906|Dispatcher-6

WBOY
Release: 2016-07-28 08:29:34
Original
1481 people have browsed it

<code><span>/**
     * Broadcast the given event class.
     *
     *<span> @param</span>  \Illuminate\Contracts\Broadcasting\ShouldBroadcast  $event
     *<span> @return</span> void
     */</span><span>protected</span><span><span>function</span><span>broadcastEvent</span><span>(<span>$event</span>)</span>
    {</span><span>// why use this function name is broadcast</span><span>// event class means event instance</span><span>if</span> (<span>$this</span>->queueResolver) {<span>// use this queueResolver function</span><span>$connection</span> = <span>$event</span><span>instanceof</span> ShouldBroadcastNow ? <span>'sync'</span> : <span>null</span>;<span>// determine this instance about</span><span>$queue</span> = method_exists(<span>$event</span>, <span>'onQueue'</span>) ? <span>$event</span>->onQueue() : <span>null</span>;<span>// determine method_exits</span><span>$this</span>->resolveQueue()->connection(<span>$connection</span>)->pushOn(<span>$queue</span>, <span>'Illuminate\Broadcasting\BroadcastEvent'</span>, [
                <span>'event'</span> => serialize(<span>clone</span><span>$event</span>),
            ]);<span>// good look bad use ,maybe</span>
        }
    }

    <span>/**
     * Get all of the listeners for a given event name.
     *
     *<span> @param</span>  string  $eventName
     *<span> @return</span> array
     */</span><span>public</span><span><span>function</span><span>getListeners</span><span>(<span>$eventName</span>)</span>
    {</span><span>// Get all of the listeners for a given event name.</span><span>$wildcards</span> = <span>$this</span>->getWildcardListeners(<span>$eventName</span>);<span>// get the wild card by eventsName use this function ,that name is cardlisters</span><span>// first use eventName</span><span>if</span> (! <span>isset</span>(<span>$this</span>->sorted[<span>$eventName</span>])) {
            <span>$this</span>->sortListeners(<span>$eventName</span>);<span>// use this sort Listeners</span>
        }<span>// if isset eventsName never be sort ,</span><span>return</span> array_merge(<span>$this</span>->sorted[<span>$eventName</span>], <span>$wildcards</span>);<span>// array_merge</span>
    }

    <span>/**
     * Get the wildcard listeners for the event.
     *
     *<span> @param</span>  string  $eventName
     *<span> @return</span> array
     */</span><span>protected</span><span><span>function</span><span>getWildcardListeners</span><span>(<span>$eventName</span>)</span>
    {</span><span>$wildcards</span> = [];<span>// getWildcardListeners() set the listener</span><span>foreach</span> (<span>$this</span>->wildcards <span>as</span><span>$key</span> => <span>$listeners</span>) {<span>// foreach $this->wildcards as key</span><span>if</span> (Str::is(<span>$key</span>, <span>$eventName</span>)) {<span>// determine is a str</span><span>$wildcards</span> = array_merge(<span>$wildcards</span>, <span>$listeners</span>); <span>// get the array_merge</span>
            }
        }

        <span>return</span><span>$wildcards</span>;
    }
<span>// first get listener,second get the wildcard listener</span></code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces [Li Jingshan php] laravel-20160906|Dispatcher-6 every day, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template