<?php
 namespace App\AutoProcessRules\Logs; class Log { public $idTransaction; public $messageType; public $messageText; public $entityType; public $idEntity; public $entityOperation; public $time; public function __construct($messageType, $messageText) { $this->setMessage($messageType, $messageText); $this->time = microtime(true); } static public function create($messageType, $messageText) { return new self($messageType, $messageText); } static public function createFromMessage(\App\Message $appMessage, $idTransaction=null) { $log = new self($appMessage->getType(), $appMessage->getTextWithField()); $log->idTransaction = $idTransaction; return $log; } public function setMessage($messageType, $messageText) { if (!in_array($messageType, ['info', 'warning', 'error', 'success'])) { throw new \Exception('Invalid message type: '.$messageType.' for AP rule log.'); } $this->messageType = $messageType; $this->messageText = $messageText; return $this; } public function setEntityDetails($entityType, $idEntity, $entityOperation=null) { $this->entityType = $entityType; $this->idEntity = $idEntity; if ($entityOperation) { $this->entityOperation = $entityOperation; } return $this; } public function setIdTransaction($idTransaction) { $this->idTransaction = $idTransaction; return $this; } } 