Created
          September 11, 2019 20:27 
        
      - 
      
 - 
        
Save BlackScorp/8c305774ec9938751a3a0ca981ba4fee to your computer and use it in GitHub Desktop.  
    Code zum Video https://youtu.be/yJRTHI6EPuA
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function event(string $name, array $data = [],callable $action = null,int $priority = 0){ | |
| static $events = []; | |
| if($action){ | |
| $events[$name][]=[ | |
| 'priority' => $priority, | |
| 'action' => $action | |
| ]; | |
| return null; | |
| } | |
| if(!isset($events[$name])){ | |
| return null; | |
| } | |
| $eventData = $events[$name]; | |
| usort($eventData,function($a,$b){ | |
| return $b['priority'] <=> $a['priority']; | |
| }); | |
| foreach($eventData as $event){ | |
| $event['action'](...$data); | |
| } | |
| return null; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment