diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 996be67..44dc3df 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -10,12 +10,10 @@ require_once(DIR_SYSTEM . 'engine/action.php'); require_once(DIR_SYSTEM . 'engine/controller.php'); - +/** @autoload class */ spl_autoload_register(function ($class) { $namespace = explode("\\", $class); - var_dump($class); - $legacy = [ 'Controller', 'Model', @@ -29,13 +27,18 @@ spl_autoload_register(function ($class) { ]; if(in_array($class, $legacy)){ - - class_alias("\\Phacil\\Framework\\".$class, $class); + try { + class_alias("\\Phacil\\Framework\\".$class, $class); + } catch (\Exception $th) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); + } + //eval("class ".$class." extends \\Phacil\\Framework\\".$class." {}"); return; } - $class = ($namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower( $class)) : $class; + $classNative = ($namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower( $class)) : $class; $allowed = [ 'log', @@ -50,16 +53,18 @@ spl_autoload_register(function ($class) { 'abstracthelper' ]; - if($namespace[0] == "Phacil" && in_array($class, $allowed)){ + if($namespace[0] == "Phacil" && in_array($classNative, $allowed)){ try { - include_once(DIR_SYSTEM . 'engine/'. $class.'.php'); + include_once(DIR_SYSTEM . 'engine/'. $classNative.'.php'); return; - } catch (\Throwable $th) { + } catch (\Exception $th) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("Class '$class' not loaded."); } } - $value = DIR_SYSTEM . $class.'/autoload.php'; + $value = DIR_SYSTEM . $classNative.'/autoload.php'; if($namespace[0] == "Phacil" && in_array($value, $this->dirs)){ try { @@ -67,9 +72,13 @@ spl_autoload_register(function ($class) { require_once $value; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$value' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } @@ -81,9 +90,13 @@ spl_autoload_register(function ($class) { require_once $tryMagicOne; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } @@ -96,12 +109,17 @@ spl_autoload_register(function ($class) { require_once $tryMagicOne; return; } else { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); } } catch (\Exception $e) { + $log = new \Phacil\Framework\Log(DIR_LOGS."exception.log"); + $log->write($class.' not loaded!'); exit($e->getMessage()); } } + return; });