6 Commits

6 changed files with 35 additions and 111 deletions

View File

@ -17,36 +17,29 @@ if ( ! defined('BEDROCK_ROOT_DIRECTORY' ) ) {
define('BEDROCK_ROOT_DIRECTORY', dirname(__DIR__) . DIRECTORY_SEPARATOR); define('BEDROCK_ROOT_DIRECTORY', dirname(__DIR__) . DIRECTORY_SEPARATOR);
} }
if ( ! defined('BEDROCK_CONFIG_DIRECTORY' ) ) { if ( ! defined('BEDROCK_CONFIG_DIRECTORY' ) ) {
define('BEDROCK_CONFIG_DIRECTORY', BEDROCK_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR); define('BEDROCK_CONFIG_DIRECTORY', BEDROCK_ROOT_DIRECTORY . 'Config' . DIRECTORY_SEPARATOR);
} }
if ( ! defined('BEDROCK_CONSTANTS_LOADED' ) ) { if ( ! defined('BEDROCK_CONSTANTS_LOADED' ) ) {
require_once BEDROCK_CONFIG_DIRECTORY . 'constants.php'; require_once BEDROCK_CONFIG_DIRECTORY . 'constants.php';
} }
if ( ! class_exists( 'TheTempusProject\Bedrock\Classes\Autoloader' ) ) { if ( class_exists( 'TheTempusProject\Hermes\Classes\Autoloader' ) ) {
if ( file_exists( BEDROCK_CLASSES_DIRECTORY . 'autoloader.php' ) ) { $autoloader = new Autoloader;
require_once BEDROCK_CLASSES_DIRECTORY . 'autoloader.php'; $autoloader->setRootFolder( BEDROCK_ROOT_DIRECTORY );
} $autoloader->addNamespace(
} 'TheTempusProject\Bedrock',
if ( ! class_exists( 'TheTempusProject\Bedrock\App' ) ) { 'Bin'
if ( file_exists( BEDROCK_ROOT_DIRECTORY . 'app.php' ) ) { );
require_once BEDROCK_ROOT_DIRECTORY . 'app.php'; $autoloader->addNamespace(
} 'TheTempusProject\Bedrock\Classes',
'Classes'
);
$autoloader->addNamespace(
'TheTempusProject\Bedrock\Functions',
'Functions'
);
$autoloader->register();
} }
$autoloader = new Autoloader; require_once 'Bedrock.php';
$autoloader->setRootFolder( BEDROCK_ROOT_DIRECTORY );
$autoloader->addNamespace(
'TheTempusProject\Bedrock',
'bin'
);
$autoloader->addNamespace(
'TheTempusProject\Bedrock\Classes',
'classes'
);
$autoloader->addNamespace(
'TheTempusProject\Bedrock\Functions',
'functions'
);
$autoloader->register();
define( 'BEDROCK_AUTOLOADED', true ); define( 'BEDROCK_AUTOLOADED', true );

View File

@ -1,78 +0,0 @@
<?php
/**
* classes/custom_exception.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/Core
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Bedrock\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

@ -16,6 +16,7 @@ namespace TheTempusProject\Bedrock\Classes;
use PDO; use PDO;
use PDOException; use PDOException;
use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Canary\Classes\CustomException;
class Database { class Database {
public static $instance = null; public static $instance = null;

View File

@ -17,6 +17,8 @@ use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Classes\Config; use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Bin\Canary as Debug; use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Views;
class Pagination extends Template { class Pagination extends Template {
//The settings that will not change //The settings that will not change
@ -154,7 +156,7 @@ class Pagination extends Template {
$pageData = (object) $pageData; $pageData = (object) $pageData;
if ( self::totalPages() <= 1 ) { if ( self::totalPages() <= 1 ) {
Components::set( 'PAGINATION', 'no pagination' ); Components::set( 'PAGINATION', '' );
} else { } else {
Components::set( 'PAGINATION', Views::simpleView( 'nav.pagination', $pageData ) ); Components::set( 'PAGINATION', Views::simpleView( 'nav.pagination', $pageData ) );
} }

View File

@ -21,6 +21,9 @@ class Session {
* @return {bool} * @return {bool}
*/ */
public static function exists( $name ) { public static function exists( $name ) {
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if ( ! Check::sessionName( $name ) ) { if ( ! Check::sessionName( $name ) ) {
return false; return false;
} }
@ -43,7 +46,7 @@ class Session {
return false; return false;
} }
$sessionName = DEFAULT_SESSION_PREFIX . $name; $sessionName = DEFAULT_SESSION_PREFIX . $name;
if ( self::exists( $sessionName ) ) { if ( self::exists( $name ) ) {
return $_SESSION[ $sessionName ]; return $_SESSION[ $sessionName ];
} }
Debug::info( "Session::get - Session not found: $sessionName" ); Debug::info( "Session::get - Session not found: $sessionName" );
@ -58,6 +61,9 @@ class Session {
* @return {bool} * @return {bool}
*/ */
public static function put( $name, $data ) { public static function put( $name, $data ) {
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if ( ! Check::sessionName( $name ) ) { if ( ! Check::sessionName( $name ) ) {
return false; return false;
} }

12
composer.lock generated
View File

@ -12,7 +12,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.thetempusproject.com/the-tempus-project/canary", "url": "https://git.thetempusproject.com/the-tempus-project/canary",
"reference": "7ce988fbd95c0d9b975e7647f2e4d7ee3d5e3aad" "reference": "35415fbf3c5888ccdb8a8695989176a120026c7f"
}, },
"require": { "require": {
"php": ">=8.1.0" "php": ">=8.1.0"
@ -48,7 +48,7 @@
"thetempusproject", "thetempusproject",
"tools" "tools"
], ],
"time": "2024-08-10T18:58:57+00:00" "time": "2024-08-20T10:26:09+00:00"
}, },
{ {
"name": "thetempusproject/hermes", "name": "thetempusproject/hermes",
@ -56,7 +56,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.thetempusproject.com/the-tempus-project/hermes", "url": "https://git.thetempusproject.com/the-tempus-project/hermes",
"reference": "171183c0abdbbdf12b3b577821636dd1c51ec752" "reference": "31c51c1a5bad2871df800c89f27ace0a49848583"
}, },
"require": { "require": {
"php": ">=8.1.0" "php": ">=8.1.0"
@ -92,7 +92,7 @@
"thetempusproject", "thetempusproject",
"tools" "tools"
], ],
"time": "2024-08-13T02:56:27+00:00" "time": "2024-08-20T10:26:47+00:00"
}, },
{ {
"name": "thetempusproject/houdini", "name": "thetempusproject/houdini",
@ -100,7 +100,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.thetempusproject.com/the-tempus-project/houdini", "url": "https://git.thetempusproject.com/the-tempus-project/houdini",
"reference": "4d2ccfb1c5f18dba9886405e7e6e2264e04e1f89" "reference": "d9e61d3f8f5d10f3fa7ba31907a4b3c1edc76614"
}, },
"require": { "require": {
"php": ">=8.1.0", "php": ">=8.1.0",
@ -137,7 +137,7 @@
"thetempusproject", "thetempusproject",
"tools" "tools"
], ],
"time": "2024-08-13T03:43:46+00:00" "time": "2024-08-20T10:30:48+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],