Made extras and arrays as fallback autoloading.

main
Robert 3 years ago
parent 7cdbd3e83f
commit a533a91190
  1. 2
      documents/folders.txt
  2. 91
      src/bootstrap/auto_loader.php
  3. 8
      src/classes/loadall.php
  4. 2
      src/compiler.php

@ -43,7 +43,7 @@ tts_framework/src
   ├── loadall.php (Creates loadall.php files if do not exist for Services & Config-Files)    ├── loadall.php (Creates loadall.php files if do not exist for Services & Config-Files)
   ├── memory_usage.php (Displays PHP Memory Usage, when debug is set)    ├── memory_usage.php (Displays PHP Memory Usage, when debug is set)
   ├── misc.php (create a short url from get_url, post_var, misc. filter FNs)    ├── misc.php (create a short url from get_url, post_var, misc. filter FNs)
│ ├── obsolete │ ├── obsolete (Anything in here, will be SKIPPED by my Compiler)
│ │ ├── http_socket_request.php (Failed to get Sockets working, use Guzzle, PHP HTTP client instead!) │ │ ├── http_socket_request.php (Failed to get Sockets working, use Guzzle, PHP HTTP client instead!)
     └── sessions_interface.php      └── sessions_interface.php
   ├── page_not_found.php (CLI or tts built in views/404 page not found error)    ├── page_not_found.php (CLI or tts built in views/404 page not found error)

@ -41,7 +41,7 @@ class Psr4AutoloaderClass {
return $this->loaded_files; return $this->loaded_files;
} }
/** /**
* Adds a base directory for a namespace prefix. * Adds a base directory for a namespace prefix.
* *
* @param string $prefix The namespace prefix. * @param string $prefix The namespace prefix.
@ -73,11 +73,11 @@ class Psr4AutoloaderClass {
* failure. * failure.
*/ */
public function load_class(string $class): false|string { public function load_class(string $class): false|string {
/** if (! strrpos($class, '\\')) {
* Semi-Fix for non-namespaced classes $ret = ($this->load_mapped_file($class . '\\', $class));
*/ if ($ret !== false) {
if (substr_count($class, '\\') < 2) { return $ret;
return ($this->load_mapped_file($class, $class)); }
} }
$prefix = $class; $prefix = $class;
while (false !== $pos = strrpos($prefix, '\\')) { while (false !== $pos = strrpos($prefix, '\\')) {
@ -89,7 +89,7 @@ class Psr4AutoloaderClass {
} }
$prefix = rtrim($prefix, '\\'); $prefix = rtrim($prefix, '\\');
} }
return false; return ($this->loader($class, $class));
} }
private function decode(false|string $var): array { private function decode(false|string $var): array {
@ -105,44 +105,27 @@ class Psr4AutoloaderClass {
return []; return [];
} }
/** protected function loader(string $prefix, string $relative_class): false | string {
* Load the mapped file for a namespace prefix and relative class. $parts = explode('\\', $prefix);
* $last = array_pop($parts);
* @param string $prefix The namespace prefix. $parts = array(implode('\\', $parts), $last);
* @param string $relative_class The relative class name. $prefix = $parts[0] ?? 'tts';
* @return mixed Boolean false if no mapped file can be loaded, or the $prefix = trim($prefix, '\\') . '\\';
* name of the mapped file that was loaded.
*/
protected function load_mapped_file(string $prefix, string $relative_class): false | string {
if ($prefix === $relative_class) {
$parts = explode('\\', $prefix);
$last = array_pop($parts);
$parts = array(implode('\\', $parts), $last);
$prefix = $parts[0] ?? 'tts';
$prefix = trim($prefix, '\\') . '\\';
$reversedParts = explode('\\', strrev($relative_class), 2); $reversedParts = explode('\\', strrev($relative_class), 2);
$relative_class = strrev($reversedParts[0]); $relative_class = strrev($reversedParts[0]);
}
if (isset($this->prefixes[$prefix]) === false) { if (isset($this->prefixes[$prefix]) === false) {
return false; return false;
} }
$fw = rtrim(\bs_tts\site_helper::get_fw_dist(), "/") . "/"; $fw = rtrim(\bs_tts\site_helper::get_fw_dist(), "/") . "/";
foreach ($this->prefixes[$prefix] as $base_dir) { foreach ($this->prefixes[$prefix] as $base_dir) {
$bd = rtrim($base_dir, "/") . "/"; $bd = rtrim($base_dir, "/") . "/";
if ($fw !== false && $prefix === 'tts\\' && $bd === $fw) { if ($fw !== false && $prefix === 'tts\\' && $bd === $fw) {
$rc = str_replace('\\', '', $relative_class); $rc = str_replace('\\', '', $relative_class);
$tts_arrays = $GLOBALS['tts_arrays'] ?? false;
$ta = $this->decode($tts_arrays);
if (count($ta) && in_array($rc, $ta)) {
if ($this->require_file($bd, "tts_arrays.php")) {
return "tts_arrays.php";
}
}
$tts_extras = $GLOBALS['tts_extras'] ?? false; $tts_extras = $GLOBALS['tts_extras'] ?? false;
$te = $this->decode($tts_extras); $te = $this->decode($tts_extras);
if (count($te) && in_array($rc, $te)) { if (count($te) && in_array($rc, $te)) {
@ -150,17 +133,41 @@ class Psr4AutoloaderClass {
return "tts_extras.php"; return "tts_extras.php";
} }
} }
}
$tts_arrays = $GLOBALS['tts_arrays'] ?? false;
$file = str_replace('\\', '/', $relative_class) . '.php'; $ta = $this->decode($tts_arrays);
if ($this->require_file($base_dir, $file)) { if (count($ta) && in_array($rc, $ta)) {
return $file; if ($this->require_file($bd, "tts_arrays.php")) {
} return "tts_arrays.php";
}
}
}
} }
return false; return false;
} }
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function load_mapped_file(string $prefix, string $relative_class): false | string {
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
foreach ($this->prefixes[$prefix] as $base_dir) {
$file = str_replace('\\', '/', $relative_class) . '.php';
if ($this->require_file($base_dir, $file)) {
return $file;
}
}
return false;
}
/** /**
* If a file exists, require it from the file system. * If a file exists, require it from the file system.
* *

@ -29,13 +29,19 @@ final class loadall {
if ($fl_handle === false) { if ($fl_handle === false) {
die("System Loader Error"); die("System Loader Error");
} }
$config_path = $root_path . ltrim($path, "/"); $config_path = $root_path . ltrim($path, "/");
if ($cdir = scandir($config_path)) { if ($cdir = scandir($config_path)) {
fwrite($fl_handle, "<?php \r\n declare(strict_types=1);\r\n"); fwrite($fl_handle, "<?php \r\n declare(strict_types=1);\r\n");
fwrite($fl_handle, "/* \r\n"); fwrite($fl_handle, "/* \r\n");
fwrite($fl_handle, "* This file is Auto-Generated, Do NOT Modify!!! Please Delete this file to update configuration! \r\n"); fwrite($fl_handle, "* This file is Auto-Generated, Do NOT Modify!!! Please Delete this file to update configuration! \r\n");
fwrite($fl_handle, "*/ \r\n"); fwrite($fl_handle, "*/ \r\n");
if (str_contains($path, "configs/")) {
fwrite($fl_handle, "use \\tts\\configure as Config; \r\n");
}
if (str_contains($path, "services/")) {
fwrite($fl_handle, "use \\tts\\registry as Reg; \r\n");
}
foreach($cdir as $key => $file) { foreach($cdir as $key => $file) {
$file = trim($file); $file = trim($file);
if ($file === '..' || $file === '.' || $file === 'loadall.php') { if ($file === '..' || $file === '.' || $file === 'loadall.php') {

@ -179,7 +179,7 @@ function rsearch(array & $file_list, string $folder, string $pattern): array {
function remove_comments(string & $str): void { function remove_comments(string & $str): void {
foreach (token_get_all($str) as $token ) { foreach (token_get_all($str) as $token ) {
if ($token[0] != T_COMMENT && if ($token[0] != \T_COMMENT &&
$token[0] != \T_DOC_COMMENT $token[0] != \T_DOC_COMMENT
) { ) {
continue; // Do nothing on NON-Comments! continue; // Do nothing on NON-Comments!

Loading…
Cancel
Save