<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>
위 내용을 포함하여 매일매일 [리징산 php] laravel-20160906|Dispatcher-6을 소개하고 있으니 PHP 튜토리얼에 관심있는 친구들에게 도움이 되었으면 좋겠습니다.