From 83d450f2b0d6466f9edb0b4974c34ebb106ad8a8 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sun, 22 Oct 2023 17:29:09 -0300 Subject: [PATCH] Autoload changes --- system/arrayClass/Aux/LegacyAux.php | 79 -------------- system/arrayClass/Aux/ModernAux.php | 80 -------------- system/arrayClass/caseInsensitiveArray.php | 38 ------- system/engine/autoload.php | 100 +++++++++++------- system/engine/controller.php | 2 +- system/exception/BadFunctionCallException.php | 19 ---- system/exception/BadMethodCallException.php | 19 ---- system/exception/DomainException.php | 19 ---- system/exception/InvalidArgumentException.php | 18 ---- system/exception/LengthException.php | 19 ---- system/exception/LogicException.php | 18 ---- system/exception/OutOfBoundsException.php | 19 ---- system/exception/OutOfRangeException.php | 19 ---- system/exception/OverflowException.php | 19 ---- system/exception/RESTException.php | 18 ---- system/exception/RangeException.php | 19 ---- system/exception/RuntimeException.php | 18 ---- system/exception/Throwable.php | 36 ------- system/exception/UnderflowException.php | 19 ---- system/exception/UnexpectedValueException.php | 19 ---- system/exception/WebApiException.php | 53 ---------- 21 files changed, 63 insertions(+), 587 deletions(-) delete mode 100644 system/arrayClass/Aux/LegacyAux.php delete mode 100644 system/arrayClass/Aux/ModernAux.php delete mode 100644 system/arrayClass/caseInsensitiveArray.php delete mode 100644 system/exception/BadFunctionCallException.php delete mode 100644 system/exception/BadMethodCallException.php delete mode 100644 system/exception/DomainException.php delete mode 100644 system/exception/InvalidArgumentException.php delete mode 100644 system/exception/LengthException.php delete mode 100644 system/exception/LogicException.php delete mode 100644 system/exception/OutOfBoundsException.php delete mode 100644 system/exception/OutOfRangeException.php delete mode 100644 system/exception/OverflowException.php delete mode 100644 system/exception/RESTException.php delete mode 100644 system/exception/RangeException.php delete mode 100644 system/exception/RuntimeException.php delete mode 100644 system/exception/Throwable.php delete mode 100644 system/exception/UnderflowException.php delete mode 100644 system/exception/UnexpectedValueException.php delete mode 100644 system/exception/WebApiException.php diff --git a/system/arrayClass/Aux/LegacyAux.php b/system/arrayClass/Aux/LegacyAux.php deleted file mode 100644 index df15728..0000000 --- a/system/arrayClass/Aux/LegacyAux.php +++ /dev/null @@ -1,79 +0,0 @@ -_container[] = $value; - } else { - $this->_container[$offset] = $value; - } - } - - /** - * Whether or not an offset exists - * - * @param string $offset An offset to check for - * @access public - * @return bool - * @abstracting ArrayAccess - */ - public function offsetExists($offset) - { - if (is_string($offset)) $offset = strtolower($offset); - return isset($this->_container[$offset]); - } - - /** - * Unsets an offset - * - * @param string $offset The offset to unset - * @access public - * @abstracting ArrayAccess - * - * @return void - */ - public function offsetUnset($offset) - { - if (is_string($offset)) $offset = strtolower($offset); - unset($this->_container[$offset]); - } - - /** - * Returns the value at specified offset - * - * @param string $offset The offset to retrieve - * @access public - * @return mixed - * @abstracting ArrayAccess - */ - public function offsetGet($offset) - { - if (is_string($offset)) $offset = strtolower($offset); - return isset($this->_container[$offset]) - ? $this->_container[$offset] - : null; - } -} \ No newline at end of file diff --git a/system/arrayClass/Aux/ModernAux.php b/system/arrayClass/Aux/ModernAux.php deleted file mode 100644 index a3b8bdc..0000000 --- a/system/arrayClass/Aux/ModernAux.php +++ /dev/null @@ -1,80 +0,0 @@ -_container[] = $value; - } else { - $this->_container[$offset] = $value; - } - } - - /** - * Whether or not an offset exists - * - * @param string $offset An offset to check for - * @access public - * @return bool - * @abstracting ArrayAccess - */ - public function offsetExists($offset): bool - { - if (is_string($offset)) $offset = strtolower($offset); - return isset($this->_container[$offset]); - } - - /** - * Unsets an offset - * - * @param string $offset The offset to unset - * @access public - * @abstracting ArrayAccess - * - * @return void - */ - public function offsetUnset($offset): void - { - if (is_string($offset)) $offset = strtolower($offset); - unset($this->_container[$offset]); - } - - /** - * Returns the value at specified offset - * - * @param string $offset The offset to retrieve - * @access public - * @return mixed - * @abstracting ArrayAccess - */ - public function offsetGet($offset): mixed - { - if (is_string($offset)) $offset = strtolower($offset); - return isset($this->_container[$offset]) - ? $this->_container[$offset] - : null; - } -} \ No newline at end of file diff --git a/system/arrayClass/caseInsensitiveArray.php b/system/arrayClass/caseInsensitiveArray.php deleted file mode 100644 index 366b03d..0000000 --- a/system/arrayClass/caseInsensitiveArray.php +++ /dev/null @@ -1,38 +0,0 @@ -_container = array_map("strtolower", $initial_array); - $this->_container = array_change_key_case($initial_array); - } - -} \ No newline at end of file diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 3c6b3b9..1119a87 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -36,6 +36,8 @@ private static $subCallClass = []; + const SEPARATOR = "\\"; + /** * * @var string @@ -70,30 +72,30 @@ * @var array */ private static $allowed = [ - 'log', - 'front', - 'controller', - 'loader', - 'model', - 'registry', - 'document', - 'response', - 'classes', - 'abstracthelper', - 'interfaces\\front', - 'interfaces\\loader', - 'interfaces\\action', - 'traits\\action', - 'interfaces\\databases', - 'interfaces\\serializer', - 'interfaces\\common\\registers', - 'interfaces\\controller', - 'interfaces\\helper', - 'interfaces\\model', - 'exception', - 'render', - 'debug', - 'restful' + 'Log', + 'Front', + 'Controller', + 'Loader', + 'Model', + 'Registry', + 'Document', + 'Response', + 'Classes', + 'AbstractHelper', + 'Interfaces\\Front', + 'Interfaces\\Loader', + 'Interfaces\\Action', + 'Traits\\Action', + 'Interfaces\\Databases', + 'Interfaces\\Serializer', + 'Interfaces\\Common\\Registers', + 'Interfaces\\Controller', + 'Interfaces\\Helper', + 'Interfaces\\Model', + 'Exception', + 'Render', + 'Debug', + 'RESTful' ]; /** @@ -251,10 +253,17 @@ * @return void */ private function prepareNamespaces() { - self::$namespace = explode("\\", self::$class); - self::$namespaceWithoutPrefix = (\Phacil\Framework\Config::NAMESPACE_PREFIX()) ? explode("\\", str_replace(\Phacil\Framework\Config::NAMESPACE_PREFIX() . "\\", "", self::$class)) : self::$namespace; + self::$namespace = explode(self::SEPARATOR, self::$class); + self::$namespaceWithoutPrefix = (\Phacil\Framework\Config::NAMESPACE_PREFIX()) ? explode(self::SEPARATOR, str_replace(\Phacil\Framework\Config::NAMESPACE_PREFIX() . self::SEPARATOR, "", self::$class)) : self::$namespace; + + if(self::isPhacil() ) { + $classPhacilOutput = array_slice(self::$namespace, 2); //2 sliced because the Phacil Namespace is Phacil\Framework + self::$classNative = implode(self::SEPARATOR, $classPhacilOutput); - self::$classNative = (isset(self::$namespace[0]) && self::$namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower(self::$class)) : self::$class; + return; + } + + self::$classNative = self::$class; } /** @@ -294,11 +303,14 @@ if (!self::isPhacil()) return false; if (in_array(self::$classNative, self::$allowed)) { - $file = \Phacil\Framework\Config::DIR_SYSTEM() . 'engine/' . str_replace("\\", "/", self::$classNative) . '.php'; - + $file = \Phacil\Framework\Config::DIR_SYSTEM() . 'engine/' . str_replace(self::SEPARATOR, "/", strtolower(self::$classNative)) . '.php'; + try { if (!self::loadClassFile($file)) { - throw new \Exception("Class ".self::$class." not loaded."); + $file = \Phacil\Framework\Config::DIR_SYSTEM() . 'engine/' . str_replace(self::SEPARATOR, "/", self::$classNative) . '.php'; + if (!self::loadClassFile($file)) { + throw new \Exception("Class " . self::$class . " not loaded."); + } } return true; } catch (\Exception $th) { @@ -346,13 +358,16 @@ if (isset(self::$namespace[2]) && self::$namespace[2] == 'Databases') { - $fileDB = \Phacil\Framework\Config::DIR_DATABASE(\Phacil\Framework\Config::DIR_SYSTEM() . "database/") . str_replace("\\", "/", self::$classNative) . '.php'; + $fileDB = \Phacil\Framework\Config::DIR_DATABASE(\Phacil\Framework\Config::DIR_SYSTEM() . "database/") . str_replace(self::SEPARATOR, "/", strtolower(self::$classNative)) . '.php'; //$fileDB = self::fileResolver($fileDB); try { if (!self::loadClassFile($fileDB)) { - throw new \Phacil\Framework\Exception($fileDB . ' does not exist', 2); + $fileDB = \Phacil\Framework\Config::DIR_DATABASE(\Phacil\Framework\Config::DIR_SYSTEM() . "database/") . str_replace(self::SEPARATOR, "/", self::$classNative) . '.php'; + if (!self::loadClassFile($fileDB)) { + throw new \Phacil\Framework\Exception($fileDB . ' does not exist', 2); + } } return true; @@ -373,12 +388,17 @@ */ private function loadEngineAutoload() { if (!self::isPhacil()) return false; - - $value = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", self::$classNative) . '/autoload.php'; - + try { + $value = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", strtolower(self::$classNative)) . '/autoload.php'; + if (self::loadClassFile($value)) { return true; + } + + $value2 = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", self::$classNative) . '/autoload.php'; + if (self::loadClassFile($value2)) { + return true; } } catch (\Exception $e) { $log = new \Phacil\Framework\Log("exception.log"); @@ -397,13 +417,17 @@ */ private function loadEngineAutoload2() { if (!self::isPhacil()) return false; - - $value = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", self::$classNative) . '.php'; - + try { + $value = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", strtolower(self::$classNative)) . '.php'; if (self::loadClassFile($value)) { return true; } + + $value2 = \Phacil\Framework\Config::DIR_SYSTEM() . str_replace('\\', "/", self::$classNative) . '.php'; + if (self::loadClassFile($value2)) { + return true; + } } catch (\Exception $e) { $log = new \Phacil\Framework\Log("exception.log"); $log->write(self::$class . ' not loaded!'); diff --git a/system/engine/controller.php b/system/engine/controller.php index 2d8bf62..6af3e36 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -260,7 +260,7 @@ abstract class Controller implements \Phacil\Framework\Interfaces\Controller { * @throws Exception * @final */ - final protected function render() { + protected function render() { foreach ($this->children as $child) { $this->data[basename($child)] = $this->getChild($child); diff --git a/system/exception/BadFunctionCallException.php b/system/exception/BadFunctionCallException.php deleted file mode 100644 index 40dc997..0000000 --- a/system/exception/BadFunctionCallException.php +++ /dev/null @@ -1,19 +0,0 @@ -