You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					28 lines
				
				516 B
			
		
		
			
		
	
	
					28 lines
				
				516 B
			| 
								 
											8 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace core\dispatchers;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use core\jobs\AsyncEventJob;
							 | 
						||
| 
								 | 
							
								use yii\queue\Queue;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class AsyncEventDispatcher implements EventDispatcher
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    private $queue;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function __construct(Queue $queue)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $this->queue = $queue;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function dispatchAll(array $events): void
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        foreach ($events as $event) {
							 | 
						||
| 
								 | 
							
								            $this->dispatch($event);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function dispatch($event): void
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $this->queue->push(new AsyncEventJob($event));
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |