Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
itsalb3rt committed Nov 24, 2019
2 parents 206bd35 + d890936 commit dc036ce
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
75 changes: 75 additions & 0 deletions Core/System/Core/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Core\System\Core\errorHandler;
/**
* Captura los errores comunes que pueden ocurrir
* dentro de un proyecto, esto no manja todos los errores del framework ya que
* otras cosas especificas como errores al pasar un url
* o errores de archivo de vista son manejados desde el controlador
* principal
*
* Maneja todos los errores faltales, warning, notice.
**/
class ErrorHandler
{

public function __construct()
{
set_error_handler([$this, 'errorHandler']);
register_shutdown_function( [$this,'fatalHandler'] );
}

public function errorHandler($errno, $errstr, $errfile, $errline)
{
if($this->is_notice($errno) || $this->is_warning($errno) || $this->is_fatal_error($errno)){
$file_without_root_dir = str_replace(str_replace(DIRECTORY_SEPARATOR,'\\',ROOT),'',$errfile);
__show_dev_messages__($errstr, "<span class='code'>$errstr</span> " . $file_without_root_dir . " <span class='code'>on line $errline</span>");
}
}

public function fatalHandler() {
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;

$error = error_get_last();

if( $error !== NULL) {
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
$file_without_root_dir = str_replace(str_replace(DIRECTORY_SEPARATOR,'\\',ROOT),'',$errfile);
__show_dev_messages__(substr($errstr,0,50) . '...' , "<p class='error-description'>$errstr</p> " . $file_without_root_dir . " <span class='code'>on line $errline</span>");
}
}

private function is_notice($errno){
switch ($errno){
case E_NOTICE:
case E_USER_NOTICE:
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_STRICT:
return true;
}
}
private function is_warning($errno){
switch ($errno){
case E_WARNING:
case E_USER_WARNING:
return true;
}
}

private function is_fatal_error($errno){
switch ($errno){
case E_ERROR:
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
return true;
}
}

}

8 changes: 3 additions & 5 deletions template/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="<?= Assets::setAssets('favicon.ico') ?>" type="image/x-icon" />
<!-- The favicon and assets is under web/assets dir -->
<link rel="shortcut icon" href="<?= Assets::setAssets('favicon.ico') ?>" type="image/x-icon"/>
<title><?= $pageTitle ?></title>
</head>
<body>
<?=
/**
* Por defecto aquí se renderizan las vistas, se puede
* personalizar hasta el punto de no remover la variable $viewContent si
* esta no existe cuando renderize una vista el contenido de esta no se
* visualizara en la pagina.
* By default all the views render in this layout, please don't touch this part if you dont know you doing
**/
$viewContent;
?>
Expand Down

0 comments on commit dc036ce

Please sign in to comment.