| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\HandlerError;
- use \ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\Addon\Config;
- use \ThurData\Servers\KerioEmail\Core\Http\Request;
- /**
- * Handles adding new records to WHMCS Module and Activity Logs
- *
- * @autor ThurData <info@thurdata.ch>
- */
- class WhmcsLogsHandler
- {
- /**
- * @var Config
- */
- private $addon;
- /**
- * @var Request
- */
- private $request;
- /**
- * @param Addon $addon
- * @param Request $request
- */
- public function __construct(Config $addon, Request $request)
- {
- $this->addon = $addon;
- $this->request = $request;
- }
- /**
- * @param mixed $responseData
- * @param array $replaceVars
- * @return $this
- */
- public function addModuleLog($responseData = [], array $replaceVars = [])
- {
- if ($this->isDebugin())
- {
- if (is_array($responseData) === false)
- {
- if (is_object($responseData))
- {
- $responseData = print_r($responseData, true);
- }
- }
- logModuleCall(
- $this->getModuleName(),
- $this->getFullAction(),
- $this->getRequestData(),
- $responseData,
- print_r($responseData, true),
- $replaceVars
- );
- }
- return $this;
- }
- /**
- * @param mixed $message
- * @param int $userId
- * @return $this
- */
- public function addActiveLog($message, $userId = 0)
- {
- if ($this->isDebugin())
- {
- if (is_string($message) === false)
- {
- $message = print_r($message, true);
- }
- logActivity($message, $userId);
- }
- return $this;
- }
- /**
- * @return array
- */
- private function getRequestData()
- {
- return array_merge($this->request->request->all(), $this->request->query->all());
- }
- /**
- * @return string
- */
- private function getModuleName()
- {
- return $this->addon->getConfigValue("name", 'KerioEmail');
- }
- /**
- * @return bool
- */
- private function isDebugin()
- {
- return (bool)((int)$this->addon->getConfigValue("debug", "0"));
- }
- /**
- * @return string
- */
- private function getFullAction()
- {
- return $this->request->get('mg-page', 'Home') . $this->request->get('mg-action', 'Index');
- }
- public function addModuleLogError(Exceptions\Exception $exception, array $replaceVars = [])
- {
- $responseData = $exception->getOriginalException();
- if (!$exception->isLogable())
- {
- return;
- }
- if (is_object($responseData))
- {
- $responseData = print_r([
- 'message' => $responseData->getMessage(),
- 'code' => $responseData->getCode(),
- 'file' => $responseData->getFile(),
- 'line' => $responseData->getLine(),
- 'trace' => $responseData->getTraceAsString(),
- //'previous' => $responseData->getPrevious()
- ], true);
- }
- if (!$responseData)
- {
- $responseData = [
- 'message' => $exception->getMgMessage(false),
- 'trace' => $exception->getTraceAsString()
- ];
- }
- logModuleCall(
- $this->getModuleName(),
- $this->getFullAction(),
- [
- 'deteils' => $exception->getDetailsToLog(),
- 'request' => $this->getRequestData()
- ],
- $responseData,
- print_r($responseData, true),
- $replaceVars
- );
- return $this;
- }
- }
|