zalazdi

Event.php

Mar 25th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Events;
  4.  
  5. abstract class Event
  6. {
  7.     protected function isNumeric($worker_id)
  8.     {
  9.         if (! is_numeric($worker_id)) {
  10.             throw new \Exception('Param $worker_id is not numeric.');
  11.         }
  12.  
  13.         return;
  14.     }
  15.  
  16.  
  17.  
  18.     /**
  19.      * Entity array contract
  20.      * @var array
  21.      */
  22.     protected $entityKeys = [
  23.         'actual',
  24.         'before',
  25.         'related',
  26.     ];
  27.  
  28.     /**
  29.      * Check entities with contract and convert entities to json format
  30.      *
  31.      * @param array $entities
  32.      * @return array
  33.      * @throws \Exception
  34.      */
  35.     protected function convertEntities($entities = []) {
  36.  
  37.         if (! empty(array_filter($entities))) {
  38.             foreach ($this->entityKeys as $key) {
  39.                 if(!array_key_exists($key, $entities)){
  40.                     $entities[$key] = null;
  41.                 } else {
  42.                     $entities[$key] = $entities[$key]->toJson();
  43.                 }
  44.             }
  45.         }
  46.  
  47.         return $entities;
  48.     }
  49.  
  50.     /**
  51.      * Assign global scope variable for actionlog
  52.      *
  53.      * @param $name
  54.      * @param $entities
  55.      * @param $note
  56.      * @throws \Exception
  57.      */
  58.     protected function assignActionlog($name, $entities, $note)
  59.     {
  60.         $this->name = $name;
  61.         $this->entities = $this->convertEntities($entities);
  62.         $this->note = $note;
  63.     }
  64. }
Add Comment
Please, Sign In to add comment