<?php

class ModuleError extends Module
{
  var $OnError;
  var $ErrorHandler;

  function __construct(System $System)
  {
    parent::__construct($System);
    $this->Name = 'Error';
    $this->Version = '1.0';
    $this->Creator = 'Chronos';
    $this->License = 'GNU/GPLv3';
    $this->Description = 'Error logging and reporting';
    $this->Dependencies = array();

    $this->OnError = array();
    $this->ErrorHandler = new ErrorHandler();
    $this->ErrorHandler->OnError[] = array($this, 'DoError');
  }

  function DoStart(): void
  {
    if (isset(Core::Cast($this->System)->Config['Web']['ShowPHPError']))
      $this->ErrorHandler->ShowError = Core::Cast($this->System)->Config['Web']['ShowPHPError'];
      else $this->ErrorHandler->ShowError = true;
    $this->ErrorHandler->Start();
  }

  function DoStop(): void
  {
    $this->ErrorHandler->Stop();
  }

  function DoError($Error)
  {
    foreach ($this->OnError as $OnError)
      call_user_func($OnError, $Error);
  }
}
