count files...

main
Robert 3 months ago
parent 3f0cec856e
commit dbfa82ef81
  1. 12
      src/bootstrap/auto_loader.php
  2. 2
      src/bootstrap/errors.php
  3. 6
      src/bootstrap/main.php
  4. 8
      src/bootstrap/requires.php
  5. 18
      src/bootstrap/site_helper.php
  6. 18
      src/classes/http/response.php
  7. 37
      src/classes/uuids/base62.php
  8. 2
      src/classes/uuids/uuidv7.php

@ -130,10 +130,14 @@ class Psr4AutoloaderClass {
private function require_file(string $path, string $file): bool { private function require_file(string $path, string $file): bool {
$safer_file = requires::safer_file_exists($file, $path); $safer_file = requires::safer_file_exists($file, $path);
if ($safer_file !== false) { if ($safer_file !== false) {
if (! isset($this->loaded_files[$safer_file])) { if (defined('CountFiles') && CountFiles) {
require $safer_file; if (! isset($this->loaded_files[$safer_file])) {
$this->loaded_files[$safer_file] = true; require $safer_file;
} $this->loaded_files[$safer_file] = true;
}
} else {
require_once $safer_file;
}
return true; return true;
} }
return false; return false;

@ -332,7 +332,7 @@ function fallback_requires(string $file, bool $fw = false, $local = null): bool
$view = CodeHydrater_FRAMEWORK . $file; $view = CodeHydrater_FRAMEWORK . $file;
} }
if (file_exists($view)) { if (file_exists($view)) {
include $view; site_helper::load_file($view);
return true; return true;
} }
} }

@ -12,7 +12,7 @@ namespace CodeHydrater\bootstrap;
$mem_baseline = memory_get_usage(); $mem_baseline = memory_get_usage();
require_once CodeHydrater_FRAMEWORK . 'bootstrap/errors.php'; site_helper::load_file(CodeHydrater_FRAMEWORK . 'bootstrap/errors.php');
final class views { final class views {
public static function ob_start(): void { public static function ob_start(): void {
@ -261,8 +261,8 @@ final class di {
// Initialize our Dependency Injector // Initialize our Dependency Injector
registry::set('di', new di()); registry::set('di', new di());
require_once CodeHydrater_FRAMEWORK . 'bootstrap/requires.php'; site_helper::load_file(CodeHydrater_FRAMEWORK . 'bootstrap/requires.php');
require_once CodeHydrater_FRAMEWORK . 'bootstrap/auto_loader.php'; site_helper::load_file(CodeHydrater_FRAMEWORK . 'bootstrap/auto_loader.php');
registry::set('loader', new Psr4AutoloaderClass); registry::set('loader', new Psr4AutoloaderClass);
registry::get('loader')->register(); registry::get('loader')->register();

@ -18,6 +18,11 @@ enum UseDir: string {
} }
final class requires { final class requires {
private static $loaded_files = [];
public static function get_loaded_files(): array {
return self::$loaded_files;
}
public static function is_valid_file(string $filename): bool { public static function is_valid_file(string $filename): bool {
if (is_string($filename) && strlen($filename) < 64) { if (is_string($filename) && strlen($filename) < 64) {
@ -174,6 +179,9 @@ final class requires {
extract($args, EXTR_PREFIX_SAME, "dup"); extract($args, EXTR_PREFIX_SAME, "dup");
} }
if (defined('CountFiles') && CountFiles) {
self::$loaded_files[] = $versioned_file;
}
if ($return_contents) { if ($return_contents) {
$script_output = (string) ob_get_clean(); $script_output = (string) ob_get_clean();
self::ob_starter(); self::ob_starter();

@ -26,7 +26,23 @@ final class site_helper {
private static $local_site_domains = ['localhost']; private static $local_site_domains = ['localhost'];
private static $Private_IPs_allowed = ['127.0.0.1', '::1']; private static $Private_IPs_allowed = ['127.0.0.1', '::1'];
private static $Public_IPs_allowed = []; private static $Public_IPs_allowed = [];
private static $loaded_files = [];
/**
* Don't USE THIS method, instead use requires::secure_include
* It validates that the file is not dangerous
*/
public static function load_file(string $file): void {
if (defined('CountFiles') && CountFiles) {
self::$loaded_files[] = $file;
}
require_once $file;
}
public static function get_loaded_files(): array {
return self::$loaded_files;
}
public static function set_local_site_domains(string|array $domain_name): void { public static function set_local_site_domains(string|array $domain_name): void {
if (is_array($domain_name)) { if (is_array($domain_name)) {
foreach($domain_name as $domain) { foreach($domain_name as $domain) {

@ -12,6 +12,8 @@ namespace CodeHydrater\http;
class response class response
{ {
use \CodeHydrater\traits\Macroable; use \CodeHydrater\traits\Macroable;
private $json = false;
public function __construct( public function __construct(
protected string $content = '', protected string $content = '',
@ -25,10 +27,22 @@ class response
foreach ($this->headers as $name => $value) { foreach ($this->headers as $name => $value) {
header("$name: $value"); header("$name: $value");
} }
echo $this->content; if ($this->status_code > 499) {
throw new \Exception($this->content);
} elseif ($this->json) {
echo $this->json;
} else {
echo $this->content;
}
} }
public function set_json(mixed $input): self {
$this->headers['Content-Type'] = 'application/json; charset=utf-8';
$this->json = json_encode($input, JSON_PRETTY_PRINT);
return $this;
}
public function get_content(): string { public function get_content(): string {
return $this->content; return $this->content;
} }

@ -0,0 +1,37 @@
<?php
declare(strict_types = 1);
/**
* @author Robert Strutts <Bob_586@Yahoo.com>
* @copyright (c) 2025, Robert Strutts
* @license MIT
*/
namespace CodeHydrater\uuids;
const BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
class base62 {
public static function encode_id(int $num): string {
if ($num === 0) return BASE62[0];
$base = strlen(BASE62);
$encoded = '';
while ($num > 0) {
$encoded = BASE62[$num % $base] . $encoded;
$num = intdiv($num, $base);
}
return $encoded;
}
public static function decode_id(string $str): int {
$base = strlen(BASE62);
$len = strlen($str);
$num = 0;
for ($i = 0; $i < $len; $i++) {
$num = $num * $base + strpos(BASE62, $str[$i]);
}
return $num;
}
}

@ -7,7 +7,7 @@ declare(strict_types = 1);
* @copyright (c) 2025, Robert Strutts * @copyright (c) 2025, Robert Strutts
* @license MIT * @license MIT
*/ */
namespace CodeHydrater; namespace CodeHydrater\uuids;
/** /**
* Description of uuidv7 * Description of uuidv7
Loading…
Cancel
Save