Esempio n. 1
0
 /**
  * Error constructor
  *
  * @param string $message
  * @param int $code
  * @param mixed $previous
  */
 public function __construct($message, $code = 0, $previous = null)
 {
     // Make sure everything is assigned properly
     parent::__construct($message, (int) $code, $previous);
     $e = $previous ? $previous : $this;
     $error = get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage();
     $info = $e->getFile() . '[' . $e->getLine() . ']';
     $debug = "Trace: \n" . $e->getTraceAsString() . "\n";
     // Get the error settings depending on environment
     $di = Di::fetch();
     if ($di->has("dump")) {
         $dump = $di->dump;
     } else {
         $dump = new Dump(true);
     }
     $err = $di->config->env->error;
     if ($err->debug) {
         // Display debug
         if (PHP_SAPI == 'cli') {
             var_dump($error, $info, $debug);
         } else {
             echo $dump->vars($error, $info, $debug);
         }
     } else {
         if (PHP_SAPI == 'cli') {
             echo $message;
         } else {
             if ($err->hide) {
                 $message = _t('somethingIsWrong');
             }
             // Load and display error view
             echo self::view($di, $code, $message);
         }
     }
     if ($err->log) {
         // Log error into the file
         $logger = new Logger(__ROOT__ . '/app/log/' . date('Ymd') . '.log');
         $logger->error($error);
         $logger->info($info);
         $logger->debug($debug);
     }
     if ($err->email) {
         // Send email to admin
         $log = $dump->vars($error, $info, $debug);
         $email = new Email();
         $email->prepare(_t('somethingIsWrong'), $di->config->app->admin, 'email/error', ['log' => $log]);
         if ($email->Send() !== true) {
             $logger = new Logger(__ROOT__ . '/app/log/' . date('Ymd') . '.log');
             $logger->error($email->ErrorInfo);
         }
     }
 }
Esempio n. 2
0
 /**
  * Send or log an email depending on environment
  */
 public function send()
 {
     if (Di::fetch()->config->env->email) {
         return parent::send();
     } else {
         $this->preSend();
         // Log email into the file
         $logger = new Logger(__ROOT__ . '/app/log/' . date('Ymd') . '.log');
         $logger->info('Subject: ' . $this->Subject . '; To: ' . json_encode($this->to));
         $logger->error($this->ErrorInfo);
         $logger->debug($this->Body);
         return true;
     }
 }