Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Events;
- abstract class Event
- {
- protected function isNumeric($worker_id)
- {
- if (! is_numeric($worker_id)) {
- throw new \Exception('Param $worker_id is not numeric.');
- }
- return;
- }
- /**
- * Entity array contract
- * @var array
- */
- protected $entityKeys = [
- 'actual',
- 'before',
- 'related',
- ];
- /**
- * Check entities with contract and convert entities to json format
- *
- * @param array $entities
- * @return array
- * @throws \Exception
- */
- protected function convertEntities($entities = []) {
- if (! empty(array_filter($entities))) {
- foreach ($this->entityKeys as $key) {
- if(!array_key_exists($key, $entities)){
- $entities[$key] = null;
- } else {
- $entities[$key] = $entities[$key]->toJson();
- }
- }
- }
- return $entities;
- }
- /**
- * Assign global scope variable for actionlog
- *
- * @param $name
- * @param $entities
- * @param $note
- * @throws \Exception
- */
- protected function assignActionlog($name, $entities, $note)
- {
- $this->name = $name;
- $this->entities = $this->convertEntities($entities);
- $this->note = $note;
- }
- }
Add Comment
Please, Sign In to add comment