diff --git a/README b/README index ea32db9..53d2794 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -# Trying To Scale - PHP 8.x Framework +# Trying To Scale - PHP 8.x micro Framework #### tts for short...is a collection of scripts I really liked...and made improvements on or made from scratch... diff --git a/gulpfile.js b/gulpfile.js index d952fc7..f35e848 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,24 +7,40 @@ const { src, dest, series, parallel, watch } = require('gulp'); const exec = require('child_process').exec; +const args = process.argv.slice(2); // Ignore node/path +var all_args = ""; +for(let i = 0; i < args.length; i++) { + all_args += " " + args[i]; +} + const php_source_files = [ '**/*.php', '!**/dist/*.php' ]; function compile_php_files() { - return new Promise(function(resolve, reject) { - exec('php -f compiler.php', function (err, stdout, stderr) { + return new Promise(function(resolve, reject) { + exec('php -f compiler.php -- ' + all_args, + function (err, stdout, stderr) { console.log(stdout); console.log(stderr); resolve(stdout); - }); + }); }); } +async function help() { + console.log(`compiler options: + --prod [will minify all files] + --dev [combines files UN-minified] + --authors [Removes all comments including authors] + `); +} + function watch_php() { - process.chdir('src'); + process.chdir('src'); watch(php_source_files, compile_php_files); } -exports.default = series(watch_php); \ No newline at end of file +exports.default = series(watch_php); +exports.help = help; \ No newline at end of file diff --git a/src/bootstrap/safer_io.php b/src/bootstrap/safer_io.php index 6f895b5..78907ce 100644 --- a/src/bootstrap/safer_io.php +++ b/src/bootstrap/safer_io.php @@ -434,7 +434,7 @@ final class safer_io { $safer_db_data = $safer_data; } else { if (isset($a->use_db_filter) && $a->use_db_filter == DB_FILTER::ON) { - $safe_for_db = \tts\safer_sql::get_safer_sql_text($safer_data); + $safe_for_db = \tts\extras\safer_sql::get_safer_sql_text($safer_data); $text = $safe_for_db["text"]; $meta[$input_field_name]['db_filter_status'] = $safe_for_db["status"] ?? \tts\SQL_SAFETY_FLAG::filtered; } else { diff --git a/src/classes/extras/bb_code_parser.php b/src/classes/extras/bb_code_parser.php index d079730..28bfda1 100644 --- a/src/classes/extras/bb_code_parser.php +++ b/src/classes/extras/bb_code_parser.php @@ -4,13 +4,13 @@ declare(strict_types=1); /** * @link https://github.com/genert/bbcode/blob/master/src/Parser/BBCodeParser.php - * The MIT License (MIT) - * Copyright (c) Genert 2017 - present. + * @license The MIT License (MIT) + * @copyright (c) Genert 2017 - present. * * Take BB code 2 HTML, to display output */ -namespace tts; +namespace tts\extras; final class bb_code_parser { protected $parsers = [ diff --git a/src/classes/extras/html_parser.php b/src/classes/extras/html_parser.php index d002549..445f684 100644 --- a/src/classes/extras/html_parser.php +++ b/src/classes/extras/html_parser.php @@ -4,13 +4,13 @@ declare(strict_types=1); /** * @link https://github.com/genert/bbcode/blob/master/src/Parser/HTMLParser.php - * The MIT License (MIT) - * Copyright (c) Genert 2017 - present. + * @license The MIT License (MIT) + * @copyright (c) Genert 2017 - present. * * Take HTML 2 BB code .. to save into db */ -namespace tts; +namespace tts\extras; final class html_parser { protected $parsers = [ diff --git a/src/classes/safer_sql.php b/src/classes/extras/safer_sql.php similarity index 99% rename from src/classes/safer_sql.php rename to src/classes/extras/safer_sql.php index c62182c..3e65308 100644 --- a/src/classes/safer_sql.php +++ b/src/classes/extras/safer_sql.php @@ -13,7 +13,7 @@ declare(strict_types=1); * Too many FALSE positives and too many FALSE Negatives!!! */ -namespace tts; +namespace tts\extras; enum SQL_SAFETY_FLAG { case good; // All Okey diff --git a/src/classes/view.php b/src/classes/view.php index a1ef1fe..5b1514a 100644 --- a/src/classes/view.php +++ b/src/classes/view.php @@ -8,12 +8,6 @@ declare(strict_types=1); * @license https://mit-license.org/ */ - -/** - * @todo Add Template Service here instead of hardcoded - * Ref to Liquid. - */ - namespace tts; final class view { diff --git a/src/compiler.php b/src/compiler.php index 24d3763..83c7aff 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -8,8 +8,8 @@ declare(strict_types=1); * @license https://mit-license.org/ */ +$show_authors = true; $debugging_AKA_non_production_mode = false; - if ($debugging_AKA_non_production_mode) { $print_new_line = true; $show_filename_comments = true; @@ -17,10 +17,42 @@ if ($debugging_AKA_non_production_mode) { $skip_extras_folder = false; } else { $print_new_line = false; - $show_filename_comments = false; + $show_filename_comments = true; $skip_mocking_data_arrays = true; $skip_extras_folder = true; } + +foreach($argv as $arg) { + if ($arg === "/?") { +?> +-prod break up mocking array data file and extras folder into separate files +-dev build one big file (non-minimized) +-authors (Removes all comment blocks, including the author/(c)) +/? this help + $extras, 'arrays' => $arrays]; } -function remove_comments(string & $str): void { +function remove_comments(string & $str): array { + $authors = []; foreach (token_get_all($str) as $token ) { if ($token[0] != \T_COMMENT && $token[0] != \T_DOC_COMMENT ) { continue; // Do nothing on NON-Comments! } + if (str_contains($token[1], "@author") || str_contains($token[1], "@copyright")) { + if (! str_contains($token[1], "Robert Strutts")) { + $authors[] = $token[1]; + } + } $str = str_replace($token[1], '', $str); // Replace comment - } + } + return $authors; } function is_folder(string $dir): bool { @@ -206,7 +251,8 @@ function compile( bool $append = false, ?string $prefix = "", ?string $postfix = "" -): void { +): void { + $show_authors = $GLOBALS['show_authors'] ?? true; $root_path = __DIR__ . '/'; is_folder($root_path); @@ -226,11 +272,14 @@ function compile( } if (! $append) { fwrite($fl_handle, " \r\n \t * @copyright Copyright (c) 2022, Robert Strutts. \r\n \t * @license MIT \r\n \t */ \r\n"); + if ($show_authors) { + fwrite($fl_handle, "\t /** \r\n \t * @link https://git.mysnippetsofcode.com/tts/tts_framework \r\n \t * @author Robert Strutts \r\n \t * @copyright Copyright (c) 2022, Robert Strutts. \r\n \t * @license MIT \r\n \t */ \r\n"); + } } if ($prefix !== null && ! empty($prefix)) { fwrite($fl_handle, $prefix); } + foreach ($files as $file) { $file_with_path = $root_path . $file; @@ -238,8 +287,8 @@ function compile( if ($content === false) { continue; } - - remove_comments($content); + + $authors = remove_comments($content); $a = explode(PHP_EOL, $content); unset($content); @@ -249,9 +298,15 @@ function compile( if ($is_php_start_block) { $is_php_start_block = false; if ($GLOBALS['show_filename_comments']) { - $line = PHP_EOL . "/* Contents of : {$file} */"; + $line = PHP_EOL . "/* Contents of : {$file} */" . PHP_EOL; fwrite($fl_handle, $line); } + if ($show_authors) { + foreach($authors as $author) { + fwrite($fl_handle, PHP_EOL); + fwrite($fl_handle, "/*" . str_replace(['/*','*/','*'], ['','',''], $author) . "*/" . PHP_EOL); + } + } continue; } @@ -281,13 +336,19 @@ function compile( '\\tts\\contacts\\', '\\tts\\traits\\database\\', '\\tts\\traits\\security\\', - '\\tts\\services\\sessions\\']; + '\\tts\\services\\sessions\\', + '\\tts\\exceptions\\', + '\\tts\\extras\\', + ]; $replace = ['tts', 'tts', '\\tts\\', '\\tts\\', '\\tts\\', '\\tts\\', - '\\tts\\']; + '\\tts\\', + '\\tts\\', + '\\tts\\', + ]; $out = str_replace($search, $replace, $line); fwrite($fl_handle, $out); }