From 7d0624c01565cbad4144c8b6d2004348d01e86b1 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sat, 9 Apr 2022 18:40:14 -0300 Subject: [PATCH] Refactoring access to config constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now the config constants is accessible from \Phacil\Framework\Config in a static method. No more 'undefined constant' in the framework 🤗 --- system/captcha/autoload.php | 26 ++++++++++++-------------- system/config/autoload.php | 2 +- system/database/autoload.php | 3 ++- system/engine/action.php | 25 +++++++++++++------------ system/engine/autoload.php | 4 ++-- system/engine/controller.php | 22 +++++++++++----------- system/engine/document.php | 26 ++++++++++++++------------ system/engine/exception.php | 4 ++-- system/engine/front.php | 8 ++++---- system/engine/loader.php | 14 ++++++++------ system/engine/render.php | 15 ++++++++------- system/engine/traits/action.php | 4 +++- system/image/autoload.php | 2 +- system/language/autoload.php | 3 ++- system/session/autoload.php | 3 ++- system/system.php | 16 ++++++++-------- system/url/autoload.php | 8 +++----- system/url/seo_url.php | 18 +++++++++--------- 18 files changed, 105 insertions(+), 98 deletions(-) diff --git a/system/captcha/autoload.php b/system/captcha/autoload.php index e7a5ef0..aeee1a6 100644 --- a/system/captcha/autoload.php +++ b/system/captcha/autoload.php @@ -8,7 +8,18 @@ namespace Phacil\Framework; -/** @package Phacil\Framework */ +/** + * Captcha module. + * + * Declare new Captcha($width, $height, $numChar, $background) on a variable, use $variable->getCode() to obtain a plain text captcha code (prefer pass thos code to a SESSION) and return $variable->showImage(\'format\'). + * + * Formats: bmp, jpg, png, wbmp and gif. + * + * @example $captcha = new Captcha($width, $height, $numChar, $background); + * + * @since 1.0.2 + * @package Phacil\Framework + */ class Captcha { protected $code; public $height = 40; @@ -53,19 +64,6 @@ class Captcha { } - /** @return void */ - public function __help() { - $helpTxt = - array( - "version" => "1.0", - "Description" => "Captcha module.", - "Use" => 'Declare new Captcha($width, $height, $numChar, $background) on a variable, use $variable->getCode() to obtain a plain text captcha code (prefer pass thos code to a SESSION) and return $variable->showImage(\'format\').', - "Formats" => "bmp, jpg, png, wbmp and gif." - ); - - var_dump($helpTxt, true); - } - /** @return string */ function getCode(){ return implode("", $this->code); diff --git a/system/config/autoload.php b/system/config/autoload.php index 33d5aa8..ef32444 100644 --- a/system/config/autoload.php +++ b/system/config/autoload.php @@ -49,7 +49,7 @@ final class Config { */ static public function __callStatic ($key, $value){ try { - return (defined($key)) ? constant($key) : self::setConstant($key, $value); + return (defined($key)) ? constant($key) : ($value ? self::setConstant($key, $value) : null); } catch (\Phacil\Framework\Exception $th) { throw new \Phacil\Framework\Exception($th->getMessage()); } diff --git a/system/database/autoload.php b/system/database/autoload.php index fa9c3a9..cfd8c98 100644 --- a/system/database/autoload.php +++ b/system/database/autoload.php @@ -9,6 +9,7 @@ namespace Phacil\Framework; use Phacil\Framework\Interfaces\Databases as DatabaseInterface; +use Phacil\Framework\Config; /** * Principal class to load databases drivers @@ -92,7 +93,7 @@ final class Database { */ public function query($sql, $cacheUse = true) { - if(defined('SQL_CACHE') && SQL_CACHE == true && $cacheUse == true) { + if(Config::SQL_CACHE() && $cacheUse == true) { return $this->Cache($sql); diff --git a/system/engine/action.php b/system/engine/action.php index 6b4da2a..82c106f 100644 --- a/system/engine/action.php +++ b/system/engine/action.php @@ -10,6 +10,7 @@ namespace Phacil\Framework; use \Phacil\Framework\Interfaces\Action as ActionInterface; use \Phacil\Framework\Traits\Action as ActionTrait; +use \Phacil\Framework\Config; /** * Action class to route all user controllers @@ -37,19 +38,19 @@ final class Action implements ActionInterface { $pathNew = $path; $path .= $part; - if (is_dir(DIR_APP_MODULAR . $path)) { + if (is_dir(Config::DIR_APP_MODULAR() . $path)) { $path = $path.'/'; array_shift($parts); continue; - }elseif (is_dir(DIR_APP_MODULAR . ucfirst($path))) { + }elseif (is_dir(Config::DIR_APP_MODULAR() . ucfirst($path))) { $path = ucfirst($path).'/'; array_shift($parts); continue; - }elseif (is_dir(DIR_APPLICATION . 'controller/' . $path)) { + }elseif (is_dir(Config::DIR_APPLICATION() . 'controller/' . $path)) { $path .= '/'; array_shift($parts); @@ -63,8 +64,8 @@ final class Action implements ActionInterface { $pregReplaceOnPath = preg_replace('/[^a-zA-Z0-9]/', '', $path); $pregReplaceOnPart = preg_replace('/[^a-zA-Z0-9]/', '', $part); - if (is_file(DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php')) { - $this->file = DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php'; + if (is_file(Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php')) { + $this->file = Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php'; $this->class = 'Controller' . $pregReplaceOnPath; @@ -78,8 +79,8 @@ final class Action implements ActionInterface { array_shift($parts); break; - } elseif (is_file(DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php')) { - $this->file = DIR_APP_MODULAR . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php'; + } elseif (is_file(Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php')) { + $this->file = Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php'; $this->class = 'Controller' . $pregReplaceOnPath; @@ -93,8 +94,8 @@ final class Action implements ActionInterface { array_shift($parts); break; - } elseif (is_file(DIR_APPLICATION . 'controller/' . $strReplaceOnPath . '.php')) { - $this->file = DIR_APPLICATION . 'controller/' . $strReplaceOnPath . '.php'; + } elseif (is_file(Config::DIR_APPLICATION() . 'controller/' . $strReplaceOnPath . '.php')) { + $this->file = Config::DIR_APPLICATION() . 'controller/' . $strReplaceOnPath . '.php'; $this->class = 'Controller' . $pregReplaceOnPath; @@ -150,7 +151,7 @@ final class ActionSystem implements ActionInterface { foreach ($parts as $part) { $path .= $part; - if (is_dir(DIR_SYSTEM . '' . $path)) { + if (is_dir(Config::DIR_SYSTEM() . '' . $path)) { $path .= '/'; array_shift($parts); @@ -158,8 +159,8 @@ final class ActionSystem implements ActionInterface { continue; } - if (is_file(DIR_SYSTEM . '' . str_replace('../', '', $path) . '.php')) { - $this->file = DIR_SYSTEM . '' . str_replace('../', '', $path) . '.php'; + if (is_file(Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php')) { + $this->file = Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php'; $this->class = 'System' . preg_replace('/[^a-zA-Z0-9]/', '', $path); diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 7c925ba..6a1a6a9 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -187,9 +187,9 @@ spl_autoload_register(function ($class) { }); -require_once(DIR_SYSTEM . 'engine/action.php'); +require_once(\Phacil\Framework\Config::DIR_SYSTEM() . 'engine/action.php'); -$composer = defined('DIR_VENDOR') ? DIR_VENDOR : DIR_SYSTEM . 'vendor/autoload.php'; +$composer = \Phacil\Framework\Config::DIR_VENDOR() ?: \Phacil\Framework\Config::DIR_VENDOR(\Phacil\Framework\Config::DIR_SYSTEM() . 'vendor/autoload.php'); if (file_exists($composer)) { /** diff --git a/system/engine/controller.php b/system/engine/controller.php index fdaeecc..d1766f2 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -12,6 +12,7 @@ use TypeError; use Mustache_Exception_UnknownTemplateException; use RuntimeException; use SmartyException; +use \Phacil\Framework\Config; /** * Extend this class to create interation with your module controller to Phacil engine controller. @@ -266,28 +267,27 @@ abstract class Controller { foreach($structure as $themefile){ - if(file_exists(DIR_APP_MODULAR .$themefile)){ + if(file_exists(Config::DIR_APP_MODULAR() .$themefile)){ $this->template = $themefile; - $templatePath = DIR_APP_MODULAR; + $templatePath = Config::DIR_APP_MODULAR(); break; } - if(file_exists(DIR_TEMPLATE .$themefile)){ + if(file_exists(Config::DIR_TEMPLATE() .$themefile)){ $this->template = $themefile; - $templatePath = DIR_TEMPLATE; + $templatePath = Config::DIR_TEMPLATE(); break; } } } } else { - //$teste = DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/" .$this->template; - if(file_exists(DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/" .$this->template)){ - $templatePath = DIR_APP_MODULAR.implode("/", $pegRoutWithoutLast)."/View/"; - } elseif(file_exists(DIR_APP_MODULAR.implode("/", $pegRoutWithoutPenultimate)."/View/" .$this->template)){ - $templatePath = DIR_APP_MODULAR.implode("/", $pegRoutWithoutPenultimate)."/View/"; + if(file_exists(Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutLast)."/View/" .$this->template)){ + $templatePath = Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutLast)."/View/"; + } elseif(file_exists(Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutPenultimate)."/View/" .$this->template)){ + $templatePath = Config::DIR_APP_MODULAR().implode("/", $pegRoutWithoutPenultimate)."/View/"; } - if(file_exists(DIR_TEMPLATE .$this->template)){ - $templatePath = DIR_TEMPLATE; + if(file_exists(Config::DIR_TEMPLATE() .$this->template)){ + $templatePath = Config::DIR_TEMPLATE(); } } diff --git a/system/engine/document.php b/system/engine/document.php index 7ba8c74..fe656ec 100644 --- a/system/engine/document.php +++ b/system/engine/document.php @@ -8,6 +8,8 @@ namespace Phacil\Framework; +use Phacil\Framework\Config; + /** @package Phacil\Framework */ class Document { private $title; @@ -23,8 +25,8 @@ class Document { * @return void */ public function setTitle($title) { - if(PATTERSITETITLE != false) { - $this->title = sprintf($title, PATTERSITETITLE); + if(Config::PATTERSITETITLE()) { + $this->title = sprintf($title, Config::PATTERSITETITLE()); } else { $this->title = $title; } @@ -84,9 +86,9 @@ class Document { */ private function checkCDN( $var) { - if(defined('CDN')) { + if(Config::CDN()) { if($this->checkLocal($var)){ - $var = CDN.$var; + $var = Config::CDN().$var; } } @@ -178,9 +180,9 @@ class Document { private function cacheMinify($ref, $type) { $dir = "css-js-cache/"; - $dirCache = DIR_PUBLIC. $dir; + $dirCache = Config::DIR_PUBLIC(). $dir; $newName = str_replace("/", "_", $ref); - $file = DIR_PUBLIC.$ref; + $file = Config::DIR_PUBLIC().$ref; $cachedFile = $dirCache.$newName; $cacheFile = $dir.$newName; @@ -192,19 +194,19 @@ class Document { mkdir($dirCache, 0755, true); } - if (file_exists($file) and defined('CACHE_MINIFY') and CACHE_MINIFY == true) { + if (file_exists($file) and Config::CACHE_MINIFY()) { if($type == "js") { - if(file_exists($cachedFile) and defined('CACHE_JS_CSS') and CACHE_JS_CSS == true) { + if(file_exists($cachedFile) and Config::CACHE_JS_CSS()) { return $cacheFile; } else { - include_once DIR_SYSTEM."ecompress/JSMin.php"; + include_once Config::DIR_SYSTEM()."ecompress/JSMin.php"; $buffer = file_get_contents($file); $buffer = preg_replace('//Uis', '', $buffer); - $buffer = JSMin::minify($buffer); + $buffer = \JSMin::minify($buffer); file_put_contents($cachedFile, $buffer); @@ -214,11 +216,11 @@ class Document { }elseif($type == "css") { - if(file_exists($cachedFile) and defined('CACHE_JS_CSS') and CACHE_JS_CSS == true) { + if(file_exists($cachedFile) && Config::CACHE_JS_CSS()) { return $cacheFile; } else { - include_once DIR_SYSTEM."ecompress/cssMin.php"; + include_once Config::DIR_SYSTEM()."ecompress/cssMin.php"; $buffer = file_get_contents($file); diff --git a/system/engine/exception.php b/system/engine/exception.php index 0402757..a1cdf3e 100644 --- a/system/engine/exception.php +++ b/system/engine/exception.php @@ -26,8 +26,8 @@ class Exception extends \Exception */ public function __destruct() { - $debugging = (defined('DEBUG')) ? DEBUG : false; - $this->errorFormat = defined('DEBUG_FORMAT') ? constant('DEBUG_FORMAT') : $this->errorFormat; + $debugging = (\Phacil\Framework\Config::DEBUG()) ?: false; + $this->errorFormat = \Phacil\Framework\Config::DEBUG_FORMAT() ?: $this->errorFormat; $log = new \Phacil\Framework\Log("exception.log"); diff --git a/system/engine/front.php b/system/engine/front.php index 69f0133..0a931ae 100644 --- a/system/engine/front.php +++ b/system/engine/front.php @@ -97,7 +97,7 @@ final class Front implements frontinterface { break; } - } catch (\Exception $th) { + } catch (Exception $th) { //throw $th; } } @@ -109,15 +109,15 @@ final class Front implements frontinterface { $action = new Action($this->error); $this->error = ''; - throw new \Exception("The controller can't be loaded", 1); + throw new Exception("The controller can't be loaded", 1); } - } catch (\Exception $th) { + } catch (Exception $th) { //throw $th; $action = new Action($this->error); $this->error = ''; - throw new \Exception("The controller can't be loaded", 1); + throw new Exception("The controller can't be loaded", 1); } diff --git a/system/engine/loader.php b/system/engine/loader.php index 998ec4c..e710453 100644 --- a/system/engine/loader.php +++ b/system/engine/loader.php @@ -8,6 +8,8 @@ namespace Phacil\Framework; + use Phacil\Framework\Config; + /** @package Phacil\Framework */ final class Loader implements \Phacil\Framework\Interfaces\Loader { protected $registry; @@ -33,7 +35,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { * @return bool */ public function library($library) { - $file = DIR_SYSTEM . 'library/' . $library . '.php'; + $file = Config::DIR_SYSTEM() . 'library/' . $library . '.php'; if (file_exists($file)) { return include_once($file); @@ -55,7 +57,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { $path = str_replace('../', '', implode("/", $parts) ); - $file = DIR_APP_MODULAR.$path."/model/". $lastPart.".php"; + $file = Config::DIR_APP_MODULAR().$path."/model/". $lastPart.".php"; if(file_exists($file)){ include_once($file); @@ -64,7 +66,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); } else { - $file = DIR_APPLICATION . 'model/' . $model . '.php'; + $file = Config::DIR_APPLICATION() . 'model/' . $model . '.php'; $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); if (file_exists($file)) { @@ -91,7 +93,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { $path = str_replace('../', '', implode("/", $parts) ); - $file = DIR_APP_MODULAR.$path."/helper/". $lastPart.".php"; + $file = Config::DIR_APP_MODULAR().$path."/helper/". $lastPart.".php"; if(file_exists($file)){ include_once($file); @@ -122,7 +124,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { * @return void */ public function controller($control) { - $file = DIR_APPLICATION . 'controller/' . $control . '.php'; + $file = Config::DIR_APPLICATION() . 'controller/' . $control . '.php'; $class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $control); if (file_exists($file)) { @@ -146,7 +148,7 @@ final class Loader implements \Phacil\Framework\Interfaces\Loader { * @return string[]|string|null */ public function database($driver, $hostname, $username, $password, $database, $port = NULL, $charset = NULL) { - $file = DIR_SYSTEM . 'database/database/' . $driver . '.php'; + $file = Config::DIR_SYSTEM() . 'database/database/' . $driver . '.php'; $class = ($driver); $replace = [ diff --git a/system/engine/render.php b/system/engine/render.php index 76b2192..0ed80ce 100644 --- a/system/engine/render.php +++ b/system/engine/render.php @@ -10,6 +10,7 @@ use Phacil\Framework\Translate; use Phacil\Framework\Registry; + use Phacil\Framework\Config; /** * @@ -188,15 +189,15 @@ * @return void */ protected function twig () { - require_once(DIR_SYSTEM . "templateEngines/Twig/autoload.php"); + require_once(Config::DIR_SYSTEM() . "templateEngines/Twig/autoload.php"); /** * @var array */ $config = array( 'autoescape' => false, - 'cache' => DIR_CACHE . "twig/", - 'debug' => (defined('DEBUG')) ? DEBUG : false + 'cache' => Config::DIR_CACHE() . "twig/", + 'debug' => Config::DEBUG()?: false ); $TwigLoaderFilesystem = constant('\TwigLoaderFilesystem'); $Twig_Environment = constant('\TwigEnvironment'); @@ -255,7 +256,7 @@ * @var \Mustache_Engine */ $mustache = new \Mustache_Engine(array( - 'cache' => DIR_CACHE . 'mustache', + 'cache' => Config::DIR_CACHE() . 'mustache', 'cache_file_mode' => 0666, 'loader' => new \Mustache_Loader_FilesystemLoader($this->templatePath), 'helpers' => array('translate' => function ($text) { @@ -285,9 +286,9 @@ $smarty = new \Smarty(); $smarty->setTemplateDir($this->templatePath); - $smarty->setCompileDir(DIR_CACHE . "Smarty/compile/"); + $smarty->setCompileDir(Config::DIR_CACHE() . "Smarty/compile/"); - $smarty->setCacheDir(DIR_CACHE . "Smarty/cache/"); + $smarty->setCacheDir(Config::DIR_CACHE() . "Smarty/cache/"); $smarty->registerPlugin("block", "translate", function ($text) { if (class_exists('Phacil\Framework\Translate')) { @@ -302,7 +303,7 @@ $smarty->caching = \Smarty::CACHING_LIFETIME_CURRENT; - $smarty->debugging = (defined('DEBUG')) ? DEBUG : false; + $smarty->debugging = Config::DEBUG() ?: false; $this->output = $smarty->display($this->template); } diff --git a/system/engine/traits/action.php b/system/engine/traits/action.php index 902a8cd..381aea9 100644 --- a/system/engine/traits/action.php +++ b/system/engine/traits/action.php @@ -8,6 +8,8 @@ namespace Phacil\Framework\Traits; +use Phacil\Framework\Config; + /** * Trait for the Action class * @@ -72,7 +74,7 @@ trait Action { } private function mountClass($namespace, $class) { - return (defined('NAMESPACE_PREFIX') ? NAMESPACE_PREFIX."\\" : "").str_replace("/", "\\", (string) $namespace)."Controller\\".(string) $class; + return (Config::NAMESPACE_PREFIX() ? Config::NAMESPACE_PREFIX()."\\" : "").str_replace("/", "\\", (string) $namespace)."Controller\\".(string) $class; } /** diff --git a/system/image/autoload.php b/system/image/autoload.php index f67db9e..6da22d1 100644 --- a/system/image/autoload.php +++ b/system/image/autoload.php @@ -61,7 +61,7 @@ final class Image { /** * @param string $image - * @return GdImage|false|void + * @return \GdImage|false|void */ private function create($image) { $info = getimagesize($image); diff --git a/system/language/autoload.php b/system/language/autoload.php index c4babd1..f6e2ddc 100644 --- a/system/language/autoload.php +++ b/system/language/autoload.php @@ -2,6 +2,7 @@ namespace Phacil\Framework; +use Phacil\Framework\Config; /** * @since 2.0.0 * @package Phacil\Framework @@ -23,7 +24,7 @@ final class Language public function load($filename) { - $file = DIR_LANGUAGE . $this->directory . '/' . $filename . '.php'; + $file = Config::DIR_LANGUAGE() . $this->directory . '/' . $filename . '.php'; if (file_exists($file)) { $_ = array(); diff --git a/system/session/autoload.php b/system/session/autoload.php index 1baffda..3461a41 100644 --- a/system/session/autoload.php +++ b/system/session/autoload.php @@ -9,6 +9,7 @@ namespace Phacil\Framework; use Phacil\Framework\Credis; +use Phacil\Framework\Config; /** * The session manipulation class @@ -72,7 +73,7 @@ final class Session */ public function __construct($redis = false, $redisDSN = null, $redisPort = null, $redisPass = null, $redis_expire = null, $redis_prefix = 'phacil_') { - $this->name = ((defined('SESSION_PREFIX')) ? SESSION_PREFIX : 'SESS') . (isset($_SERVER['REMOTE_ADDR']) ? md5($_SERVER['REMOTE_ADDR']) : md5(date("dmY"))); + $this->name = (Config::SESSION_PREFIX() ?: 'SESS') . (isset($_SERVER['REMOTE_ADDR']) ? md5($_SERVER['REMOTE_ADDR']) : md5(date("dmY"))); if (!session_id()) { $this->openSession(); diff --git a/system/system.php b/system/system.php index a44ef61..ca79ea1 100644 --- a/system/system.php +++ b/system/system.php @@ -235,7 +235,7 @@ final class startEngineExacTI { */ public function extraRegistrations() { - if(file_exists(DIR_SYSTEM."registrations.php")) + if(file_exists(\Phacil\Framework\Config::DIR_SYSTEM()."registrations.php")) include(DIR_SYSTEM."registrations.php"); } @@ -345,7 +345,7 @@ $engine->load = new Loader($engine->registry); $engine->config = new Config(); if(defined('DB_DRIVER')) - $engine->db = new Database(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); + $engine->db = new Database(\Phacil\Framework\Config::DB_DRIVER(), \Phacil\Framework\Config::DB_HOSTNAME(), \Phacil\Framework\Config::DB_USERNAME(), \Phacil\Framework\Config::DB_PASSWORD(), \Phacil\Framework\Config::DB_DATABASE()); // Settings if(!empty($configs)){ @@ -354,9 +354,9 @@ if(!empty($configs)){ } } -if(USE_DB_CONFIG === true) { +if(\Phacil\Framework\Config::USE_DB_CONFIG() === true) { - $query = (defined('CUSTOM_DB_CONFIG')) ? $engine->db->query(CUSTOM_DB_CONFIG) : $engine->db->query("SELECT * FROM settings ORDER BY setting_id ASC"); + $query = (\Phacil\Framework\Config::CUSTOM_DB_CONFIG()) ? $engine->db->query(\Phacil\Framework\Config::CUSTOM_DB_CONFIG()) : $engine->db->query("SELECT * FROM settings ORDER BY setting_id ASC"); foreach ($query->rows as $setting) { if (!$setting['serialized']) { @@ -368,8 +368,8 @@ if(USE_DB_CONFIG === true) { } -$engine->config->set('config_url', HTTP_URL); -$engine->config->set('config_ssl', HTTPS_URL); +$engine->config->set('config_url', \Phacil\Framework\Config::HTTP_URL()); +$engine->config->set('config_ssl', \Phacil\Framework\Config::HTTPS_URL()); //timezone if($engine->config->get('date_timezone')){ @@ -497,13 +497,13 @@ if($engine->controllerPreActions()){ if (isset($engine->request->get['route'])) { $action = new Action($engine->request->get['route']); } else { - $default = (defined('DEFAULT_ROUTE')) ? DEFAULT_ROUTE : 'common/home'; + $default = (\Phacil\Framework\Config::DEFAULT_ROUTE()) ? \Phacil\Framework\Config::DEFAULT_ROUTE() : \Phacil\Framework\Config::DEFAULT_ROUTE('common/home'); $engine->request->get['route'] = $default; $action = new Action($default); } // Dispatch -$not_found = (defined('NOT_FOUND')) ? NOT_FOUND : 'error/not_found'; +$not_found = (\Phacil\Framework\Config::NOT_FOUND()) ? \Phacil\Framework\Config::NOT_FOUND() : \Phacil\Framework\Config::NOT_FOUND('error/not_found'); $frontController->dispatch($action, ($not_found)); // Output diff --git a/system/url/autoload.php b/system/url/autoload.php index 267aaec..ced64fd 100644 --- a/system/url/autoload.php +++ b/system/url/autoload.php @@ -8,6 +8,8 @@ namespace Phacil\Framework; +use Phacil\Framework\Config; + class Url { /** @@ -48,11 +50,7 @@ class Url { public function __construct($url, $ssl) { $this->url = $url; $this->ssl = $ssl; - if(defined('CDN')) { - $this->cdn = CDN; - } else { - $this->cdn = false; - } + $this->cdn = Config::CDN() ?: false; if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) { $this->baseurl = $ssl; diff --git a/system/url/seo_url.php b/system/url/seo_url.php index 0b85a70..e963c0f 100644 --- a/system/url/seo_url.php +++ b/system/url/seo_url.php @@ -10,6 +10,7 @@ use Phacil\Framework\Action; use Phacil\Framework\Controller as ControllerController; use Phacil\Framework\Registry; +use Phacil\Framework\Config; class SystemUrlSeoUrl extends ControllerController { @@ -37,9 +38,8 @@ class SystemUrlSeoUrl extends ControllerController { { parent::__construct($registry); - if(defined("NOT_FOUND")) { - $this->notfound = NOT_FOUND; - } + $this->notfound = Config::NOT_FOUND() ?: $this->notfound; + } /** @return Action|void */ @@ -57,7 +57,7 @@ class SystemUrlSeoUrl extends ControllerController { $parts = array($this->request->get['_route_']); foreach ($parts as $part) { - if(defined('USE_DB_CONFIG') && USE_DB_CONFIG == true) + if(Config::USE_DB_CONFIG()) $query = $this->db->query("SELECT * FROM url_alias WHERE keyword = '" . $this->db->escape($part) . "'"); if (isset($query) && $query != false && $query->num_rows === 1) { @@ -75,8 +75,8 @@ class SystemUrlSeoUrl extends ControllerController { $this->request->get['route'] = $query->row['query']; - } elseif (defined('ROUTES') && is_array(ROUTES)) { - $rotas = ROUTES; + } elseif (Config::ROUTES() && is_array(Config::ROUTES())) { + $rotas = Config::ROUTES(); if(isset($rotas[$part])){ $this->request->get['route'] = $rotas[$part]; @@ -147,13 +147,13 @@ class SystemUrlSeoUrl extends ControllerController { foreach ($data as $key => $value) { if (isset($data['route'])) { - if(defined('USE_DB_CONFIG') && USE_DB_CONFIG == true) + if(Config::USE_DB_CONFIG()) $query = $this->db->query("SELECT * FROM url_alias WHERE `query` = '" . $this->db->escape($value) . "'"); if (isset($query) && $query->num_rows && $query->num_rows != NULL) { $url .= '/' . $query->row['keyword']; - } elseif (defined('ROUTES') && is_array(ROUTES)) { + } elseif (Config::ROUTES() && is_array(Config::ROUTES())) { //$arV = array_search($value, ROUTES); - foreach(ROUTES as $query => $page) { + foreach(Config::ROUTES() as $query => $page) { if($page == $value){ if(isRegularExpression($query)){ unset($data['route']);