diff --git a/.gitignore b/.gitignore index 212e57c..cdb5e15 100644 --- a/.gitignore +++ b/.gitignore @@ -346,4 +346,6 @@ config.php system/registrations.php -*.lst \ No newline at end of file +*.lst + +phpDocumentor.phar \ No newline at end of file diff --git a/config.dist.php b/config.dist.php index 80bc52d..03600ea 100644 --- a/config.dist.php +++ b/config.dist.php @@ -22,6 +22,7 @@ $configs = array('PatternSiteTitle'=>' - ExacTI phacil', //App folders define('DIR_APPLICATION', '/patch/to/app/folder/'); +define('DIR_APP_MODULAR', '/patch/to/app/folder/'); define('DIR_LOGS', DIR_APPLICATION.'logs/'); define('DIR_PUBLIC', DIR_APPLICATION.'public_html/'); define('DIR_SYSTEM', DIR_APPLICATION.'system/'); diff --git a/system/caches/phpfastcache.php b/system/caches/phpfastcache.php index 902a8ac..445a930 100644 --- a/system/caches/phpfastcache.php +++ b/system/caches/phpfastcache.php @@ -1,9 +1,9 @@ registry; + } + $this->registry = $registry; + } + + public function __get($key) { + return $this->registry->get($key); + } + + public function __set($key, $value) { + $this->registry->set($key, $value); + } +} diff --git a/system/engine/action.php b/system/engine/action.php index bee95ed..ef3fc2b 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -22,6 +22,7 @@ final class Action { */ public function __construct($route, $args = array()) { $path = ''; + $pathC = ""; $parts = explode('/', str_replace('../', '', (string)$route)); @@ -34,6 +35,12 @@ final class Action { array_shift($parts); + continue; + }elseif (is_dir(DIR_APP_MODULAR . ucfirst($path))) { + $path = ucfirst($path).'/'; + + array_shift($parts); + continue; }elseif (is_dir(DIR_APPLICATION . 'controller' . $path)) { $path .= '/'; @@ -43,8 +50,16 @@ final class Action { continue; } - if (is_file(DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'controller/' . str_replace('../', '', $part) . '.php')) { - $this->file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'controller/' . str_replace('../', '', $part) . '.php'; + if (is_file(DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', $part) . '.php')) { + $this->file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', $part) . '.php'; + + $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); + + array_shift($parts); + + break; + } elseif (is_file(DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', ucfirst($part)) . '.php')) { + $this->file = DIR_APP_MODULAR . str_replace('../', '', $pathNew) . 'Controller/' . str_replace('../', '', ucfirst($part)) . '.php'; $this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path); diff --git a/system/engine/autoload.php b/system/engine/autoload.php index fdd43b5..4a8f228 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -6,23 +6,35 @@ * Phacil PHP Framework - https://github.com/exacti/phacil-framework */ -//require_once(DIR_SYSTEM . 'engine/log.php'); + require_once(DIR_SYSTEM . 'engine/action.php'); require_once(DIR_SYSTEM . 'engine/controller.php'); -/* require_once(DIR_SYSTEM . 'engine/front.php'); -require_once(DIR_SYSTEM . 'engine/loader.php'); -require_once(DIR_SYSTEM . 'engine/model.php'); -require_once(DIR_SYSTEM . 'engine/registry.php'); -require_once(DIR_SYSTEM . 'engine/document.php'); -require_once(DIR_SYSTEM . 'engine/response.php'); -require_once(DIR_SYSTEM . 'engine/classes.php'); */ -//require_once(DIR_SYSTEM . 'engine/caches.php'); spl_autoload_register(function ($class) { $namespace = explode("\\", $class); - $class = str_replace('phacil\framework\\', '', strtolower( $class)); + var_dump($class); + + $legacy = [ + 'Controller', + 'Model', + 'Document', + 'Captcha', + 'Caches', + 'Pagination', + 'Request', + 'Mail', + 'Translate' + ]; + + if(in_array($class, $legacy)){ + + eval("class ".$class." extends \\Phacil\\Framework\\".$class." {}"); + return; + } + + $class = ($namespace[0] == "Phacil") ? str_replace('phacil\\framework\\', '', strtolower( $class)) : $class; $allowed = [ 'log', @@ -34,18 +46,64 @@ spl_autoload_register(function ($class) { 'document', 'response', 'classes', - //'caches' + 'abstracthelper' ]; if($namespace[0] == "Phacil" && in_array($class, $allowed)){ try { include_once(DIR_SYSTEM . 'engine/'. $class.'.php'); + return; } catch (\Throwable $th) { - throw new \Exception("Class not load"); + throw new \Exception("Class '$class' not loaded."); + } + } + + $value = DIR_SYSTEM . $class.'/autoload.php'; + + if($namespace[0] == "Phacil" && in_array($value, $this->dirs)){ + try { + if(is_readable($value)) { + require_once $value; + return; + } else { + throw new \Exception("I can't load '$value' file! Please check system permissions."); + } + } catch (\Exception $e) { + exit($e->getMessage()); + } + } + + + if(file_exists($tryMagicOne = DIR_APP_MODULAR. implode("/", $namespace).".php")){ + try { + if(is_readable($tryMagicOne)) { + require_once $tryMagicOne; + return; + } else { + throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); + } + } catch (\Exception $e) { + exit($e->getMessage()); + } + } + + $prefix = array_shift($namespace); + + if(file_exists($tryMagicOne = DIR_APP_MODULAR. implode("/", $namespace).".php")){ + try { + if(is_readable($tryMagicOne)) { + require_once $tryMagicOne; + return; + } else { + throw new \Exception("I can't load '$tryMagicOne' file! Please check system permissions."); + } + } catch (\Exception $e) { + exit($e->getMessage()); } } + return; }); -require_once(DIR_SYSTEM . 'engine/legacy.php'); \ No newline at end of file +//require_once(DIR_SYSTEM . 'engine/legacy.php'); \ No newline at end of file diff --git a/system/engine/legacy.php b/system/engine/legacy.php deleted file mode 100644 index 974bb03..0000000 --- a/system/engine/legacy.php +++ /dev/null @@ -1,13 +0,0 @@ -registry; + } $this->registry = $registry; } diff --git a/system/system.php b/system/system.php index f40fa2e..49499a2 100644 --- a/system/system.php +++ b/system/system.php @@ -148,32 +148,10 @@ class startEngineExacTI { */ private function loadengine () { $this->dirs = glob(DIR_SYSTEM.'*/autoload.php', GLOB_BRACE); - - require_once (DIR_SYSTEM.'engine/autoload.php'); - - require_once (DIR_SYSTEM.'database/autoload.php'); - - spl_autoload_register(function ($class) { - $namespace = explode("\\", $class); - - $class = str_replace('phacil\framework\\', '', strtolower( $class)); - - $value = DIR_SYSTEM . $class.'/autoload.php'; - if($namespace[0] == "Phacil" && in_array($value, $this->dirs)){ - try { - if(is_readable($value)) { - require_once $value; - } else { - throw new \Exception("I can't load '$value' file! Please check system permissions."); - } - } catch (\Exception $e) { - exit($e->getMessage()); - } - } - - }); + require_once (DIR_SYSTEM.'database/autoload.php'); + require_once (DIR_SYSTEM.'engine/autoload.php'); } /** @@ -248,6 +226,8 @@ class startEngineExacTI { } +global $engine; + /** @var \Phacil\Framework\startEngineExacTI $engine */ $engine = new startEngineExacTI();