diff --git a/.gitignore b/.gitignore index 0502b36..5b672c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock /vendor/ /nbproject/ +/src/dist/ diff --git a/documents/folders.txt b/documents/folders.txt index 93fec1b..231d7d1 100644 --- a/documents/folders.txt +++ b/documents/folders.txt @@ -88,3 +88,6 @@ tts_framework/src └── prod_errors.php (when Live, this: Sorry, we had an error... Page is used) ~70 files + +/src/compiler.php (the PHP Compiler) +/src/dist/tts.php (the Compiled framework, all in one-file!!) \ No newline at end of file diff --git a/src/bootstrap/auto_loader.php b/src/bootstrap/auto_loader.php index d4ef872..b3826fe 100644 --- a/src/bootstrap/auto_loader.php +++ b/src/bootstrap/auto_loader.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace bs_tts; + /** * @author http://php-fig.org/ * @site https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md diff --git a/src/bootstrap/errors.php b/src/bootstrap/errors.php index 390b78d..091808b 100644 --- a/src/bootstrap/errors.php +++ b/src/bootstrap/errors.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace bs_tts; + /** * @author Robert Strutts * @copyright Copyright (c) 2022, Robert Strutts. @@ -9,11 +11,14 @@ declare(strict_types=1); */ define('WORD_WRAP_CHRS', 80); // Letters before Line Wrap on Errors -$root = \bs_tts\site_helper::get_root(); -if (!defined('TTS_PROJECT_LOGS_DIR')) { - if (! empty($root)) { - define('TTS_PROJECT_LOGS_DIR', $root . 'logs'); - } + +function get_log_root_dir(): void { + $root = \bs_tts\site_helper::get_root(); + if (!defined('TTS_PROJECT_LOGS_DIR')) { + if (! empty($root)) { + define('TTS_PROJECT_LOGS_DIR', $root . 'logs'); + } + } } /** @@ -54,7 +59,7 @@ function tts_mini_view(string $file, string $msg): string { $saved_ob_level = ob_get_level(); - $mini = new stdClass(); + $mini = new \stdClass(); $mini->page_output = $msg; if (\bs_tts\requires::secure_include($file, 'on_error', $mini) === false) { \bs_tts\requires::secure_include("views/on_error/" . $file, 'tts', $mini); @@ -99,6 +104,8 @@ function tts_email_error($a_error): bool { return false; } + get_log_root_dir(); + if (!defined("TTS_PROJECT_LOGS_DIR")) { return false; } @@ -202,7 +209,7 @@ function tts_json_error_handler($data) { $data = wordwrap($data, WORD_WRAP_CHRS, "
\n"); try { - $exists = \main_tts\registry::get('di')->exists('log'); + $exists = \main_tts\registry::get('di')?->exists('log'); if ($exists) { $logs = \main_tts\registry::get('di')->get_service('log', ['all_errors']); $logs->write($data); @@ -277,16 +284,16 @@ function tts_exception_handler(\Throwable $exception) { exit(1); } -set_exception_handler('tts_exception_handler'); +set_exception_handler(__NAMESPACE__.'\tts_exception_handler'); if (\main_tts\is_live()) { error_reporting(E_ALL ^ E_NOTICE); - set_error_handler('tts_global_error_handler', E_ALL ^ (E_NOTICE | E_USER_NOTICE)); + set_error_handler(__NAMESPACE__.'\tts_global_error_handler', E_ALL ^ (E_NOTICE | E_USER_NOTICE)); } else { error_reporting(E_ALL); } -register_shutdown_function('tts_custom_error_checker'); +register_shutdown_function(__NAMESPACE__.'\tts_custom_error_checker'); /** * Custom Error Checked called on Script Shutdown. diff --git a/src/classes/arrays/common.php b/src/classes/arrays/common_stuff.php similarity index 99% rename from src/classes/arrays/common.php rename to src/classes/arrays/common_stuff.php index 6354840..81810c9 100644 --- a/src/classes/arrays/common.php +++ b/src/classes/arrays/common_stuff.php @@ -3,7 +3,7 @@ declare(strict_types=1); namespace tts\arrays; -class common { +class common_stuff { public static function get_ordinal_number_suffix(int $number): string { $number = abs($number); diff --git a/src/classes/security.php b/src/classes/security.php index 438eef5..b3e94a6 100644 --- a/src/classes/security.php +++ b/src/classes/security.php @@ -12,8 +12,8 @@ namespace tts; final class security { - use traits\security\csrf_token_functions; - use traits\security\session_hijacking_functions; + use \tts\traits\security\csrf_token_functions; + use \tts\traits\security\session_hijacking_functions; /** * Get unique IDs for database diff --git a/src/classes/services/http_requests/http_curl_request.php b/src/classes/services/http_requests/http_curl_request.php index 9ce3a68..a64e23f 100644 --- a/src/classes/services/http_requests/http_curl_request.php +++ b/src/classes/services/http_requests/http_curl_request.php @@ -10,8 +10,6 @@ declare(strict_types=1); namespace tts\services\http_requests; -use \tts\contacts\http_request_options as HTTP_Requests; - class http_curl_request { private $_status; @@ -35,7 +33,7 @@ class http_curl_request { return $this->_header_response; } - public function http_request(HTTP_Requests $options) { + public function http_request(\tts\contacts\http_request_options $options) { $uri = $options->get_uri(); $action_path = $uri; if (\bs_tts\common::is_string_found($uri, "://") === false) { diff --git a/src/classes/services/obsolete/http_socket_request.php b/src/classes/services/obsolete/http_socket_request.php index 2bb5390..81ef70e 100644 --- a/src/classes/services/obsolete/http_socket_request.php +++ b/src/classes/services/obsolete/http_socket_request.php @@ -14,11 +14,9 @@ declare(strict_types=1); namespace tts\services\obsolete\http_requests; -use \tts\contacts\http_request_options as HTTP_Requests; - final class http_socket_request { - public function http_request(HTTP_Requests $options) { + public function http_request(\tts\contacts\http_request_options $options) { $ret = ''; $verb = strtoupper( $options->get_verb() ); $cookie_str = ''; diff --git a/src/compiler.php b/src/compiler.php index 7162fed..54223f4 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -23,7 +23,6 @@ function single_file(): void { $loader_files = []; $loader_files[] = "bootstrap/auto_loader.php"; $loader_files[] = "bootstrap/errors.php"; - $loader_files[] = "bootstrap/html_purifier.php"; $loader_files[] = "bootstrap/site_helper.php"; compile($loader_files, "tts.php", false, "namespace tts;"); pop_bs($bootstap_files, $loader_files); @@ -186,8 +185,7 @@ function compile( ! str_contains($line, "fwrite(") && ! str_contains($line, "str_contains(") ) || - str_contains($line, "namespace ") || - str_contains($line, "use ") + str_contains($line, "namespace ") ) { continue; } @@ -197,8 +195,18 @@ function compile( )) { continue; } - $search = ['bs_tts', 'main_tts']; - $replace = ['tts', 'tts']; + $search = ['bs_tts', 'main_tts', + '\\tts\\enum\\', + '\\tts\\contacts\\', + '\\tts\\traits\\database\\', + '\\tts\\traits\\security\\', + '\\tts\\services\\sessions\\']; + $replace = ['tts', 'tts', + '\\tts\\', + '\\tts\\', + '\\tts\\', + '\\tts\\', + '\\tts\\']; $out = str_replace($search, $replace, $line); fwrite($fl_handle, $out); } @@ -209,3 +217,5 @@ function compile( fclose($fl_handle); chmod($tts_file, 0664); } + +echo "Compiled tts_framework into folder: dist"; \ No newline at end of file diff --git a/src/main.inc.php b/src/main.inc.php index af0d475..a5309dc 100644 --- a/src/main.inc.php +++ b/src/main.inc.php @@ -17,8 +17,16 @@ unset($_POST); $mem_baseline = memory_get_usage(); const TTS_FRAMEWORK = __DIR__ . '/'; + $up_one = dirname(__DIR__, 1); -define("TTS_VENDOR", $up_one . "/vendor/"); +if (is_dir($up_one . '/vendor')) { + $vendor = $up_one; +} else { + $up_two = dirname(__DIR__, 2); + $vendor = $up_two; +} + +define("TTS_VENDOR", $vendor . "/vendor/"); final class views { public static function ob_start(): void { @@ -277,7 +285,7 @@ require_once TTS_FRAMEWORK . 'bootstrap/common.php'; require_once TTS_FRAMEWORK . 'bootstrap/requires.php'; require_once TTS_FRAMEWORK . 'bootstrap/auto_loader.php'; -registry::set('loader', new \Psr4AutoloaderClass); +registry::set('loader', new \bs_tts\Psr4AutoloaderClass); registry::get('loader')->register(); registry::get('loader')->add_namespace("bs_tts", TTS_FRAMEWORK . "bootstrap"); registry::get('loader')->add_namespace("tts", TTS_FRAMEWORK . "classes"); @@ -285,4 +293,6 @@ registry::get('loader')->add_namespace("tts", TTS_FRAMEWORK . "tests"); require_once TTS_FRAMEWORK . 'bootstrap/errors.php'; -\bs_tts\site_helper::set_project_namespace(); \ No newline at end of file +function set_ns() { + \bs_tts\site_helper::set_project_namespace(); +} \ No newline at end of file