4 Commits
1.0.2 ... 1.0.5

Author SHA1 Message Date
35415fbf3c bugfixes + add customException from bedrock 2024-08-20 06:26:09 -04:00
7ce988fbd9 improve line limit and add config for it 2024-08-10 14:58:57 -04:00
c81d20f018 bugfix 2024-08-10 14:15:17 -04:00
289f35cf6b add logs folder 2024-08-09 17:13:37 -04:00
5 changed files with 90 additions and 5 deletions

View File

@ -226,8 +226,8 @@ class Canary {
if ( ! CANARY_ENABLED ) {
return;
}
if ( strlen( self::$debugLog ) > 50000 ) {
self::$tempusDebugger->log( 'Error log too large, possible loop.' );
if ( strlen( self::$debugLog ) > CANARY_DEBUG_LOG_LIMIT ) {
self::$tempusLogger->addLog( 'log', 'Error log too large, possible loop.' );
return;
}
if ( is_object( $data ) ) {

View File

@ -18,7 +18,7 @@ if ( !defined( 'CANARY_ROOT_DIRECTORY' ) ) {
}
if ( ! defined('CANARY_CONFIG_DIRECTORY' ) ) {
define('CANARY_CONFIG_DIRECTORY', CANARY_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR);
define('CANARY_CONFIG_DIRECTORY', CANARY_ROOT_DIRECTORY . 'Config' . DIRECTORY_SEPARATOR);
}
if ( ! defined('CANARY_CONSTANTS_LOADED' ) ) {
@ -30,12 +30,14 @@ if ( class_exists( 'TheTempusProject\Hermes\Classes\Autoloader' ) ) {
$autoloader->setRootFolder( CANARY_ROOT_DIRECTORY );
$autoloader->addNamespace(
'TheTempusProject\Canary\Classes',
'classes'
'Classes'
);
$autoloader->addNamespace(
'TheTempusProject\Canary',
'bin'
'Bin'
);
$Autoloader->register();
define( 'CANARY_AUTOLOADED', true );
}
require_once 'Canary.php';

View File

@ -0,0 +1,78 @@
<?php
/**
* Classes/CustomException.php
*
* This class is used exclusively when throwing predefined exceptions.
* It will intercept framework thrown exceptions and deal with them however
* you choose; in most cases by logging them and taking appropriate responses
* such as redirecting to error pages.
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com/Canary
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Canary\Classes;
use Exception;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Canary\Bin\Canary as Debug;
class CustomException extends Exception {
private $originFunction = null;
private $exceptionName = null;
private $originClass = null;
private $data = null;
/**
* This function allows the application to deal with errors
* in a dynamic way by letting you customize the response
*
* @param string $type - The type of the exception being called/thrown.
* @param string $data - Any additional data being passed with the exception.
*
* @example - throw new CustomException('model'); - Calls the model-missing exception
*/
public function __construct( $type, $data = null ) {
$this->originFunction = debug_backtrace()[1]['function'];
$this->originClass = debug_backtrace()[1]['class'];
$this->exceptionName = $type;
$this->data = $data;
switch ( $type ) {
case 'model':
Debug::error( 'Model not found: ' . $data );
break;
case 'dbConnection':
Debug::error( 'Error Connecting to the database: ' . $data );
break;
case 'DB':
Debug::error( 'Unspecified database error: ' . $data );
break;
case 'view':
Debug::error( 'View not found: ' . $data );
break;
case 'controller':
Debug::error( 'Controller not found: ' . $data );
Redirect::to( 404 );
break;
case 'defaultController':
Debug::error( 'DEFAULT Controller not found: ' . $data );
Redirect::to( 404 );
break;
case 'method':
Debug::error( 'Method not found: ' . $data );
Redirect::to( 404 );
break;
case 'simpleView':
Debug::error( 'View not found: ' . $data );
break;
case 'defaultMethod':
Debug::error( 'DEFAULT Method not found: ' . $data );
Redirect::to( 404 );
break;
default:
Debug::error( 'Default exception: ' . $data );
break;
}
}
}

View File

@ -48,6 +48,9 @@ if ( ! defined( 'CANARY_SHOW_LINES' ) ) {
if ( ! defined('CANARY_DEBUG_TO_CONSOLE' ) ) {
define( 'CANARY_DEBUG_TO_CONSOLE', false );
}
if ( ! defined('CANARY_DEBUG_LOG_LIMIT' ) ) {
define( 'CANARY_DEBUG_LOG_LIMIT', 500000 );
}
# Tell the app all constants have been loaded.
if ( ! defined('CANARY_CONSTANTS_LOADED' ) ) {

2
logs/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore