From a460d1f81fa1707d4354e81201ea80c223f9890a Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Mon, 6 May 2019 10:42:48 -0300 Subject: [PATCH] New registry engine system, more cache configs, auto legacy cache for PHP 5, bugfix encrypt library to web friendly format, now minimum PHP version is 5.4.20. --- README.md | 15 +- composer.json | 2 +- system/caches/autoload.php | 119 ++--------- system/caches/caches.php | 6 +- system/caches/phpfastcache.php | 109 ++++++++++ system/engine/VERSION | 2 +- system/engine/autoload.php | 2 +- system/engine/caches.php | 3 - system/library/encryption.php | 211 ++++++++++---------- system/system.php | 349 +++++++++++++++++---------------- 10 files changed, 421 insertions(+), 397 deletions(-) create mode 100644 system/caches/phpfastcache.php delete mode 100644 system/engine/caches.php diff --git a/README.md b/README.md index ac28593..3513a44 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Phacil-framework - ![GitHub](https://img.shields.io/github/license/exacti/phacil-framework.svg) ![GitHub top language](https://img.shields.io/github/languages/top/exacti/phacil-framework.svg) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/exacti/phacil-framework.svg) ![GitHub issues](https://img.shields.io/github/issues/exacti/phacil-framework.svg) ![PHP Version](https://img.shields.io/badge/php-%3E%3D5.3.29-blue.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/exacti/phacil-framework.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/exacti/phacil-framework.svg) ![GitHub release](https://img.shields.io/github/release/exacti/phacil-framework.svg) + ![GitHub](https://img.shields.io/github/license/exacti/phacil-framework.svg) ![GitHub top language](https://img.shields.io/github/languages/top/exacti/phacil-framework.svg) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/exacti/phacil-framework.svg) ![GitHub issues](https://img.shields.io/github/issues/exacti/phacil-framework.svg) ![PHP Version](https://img.shields.io/badge/php-%3E%3D5.4.20-blue.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/exacti/phacil-framework.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/exacti/phacil-framework.svg) ![GitHub release](https://img.shields.io/github/release/exacti/phacil-framework.svg) A super easy PHP Framework for web development! @@ -8,7 +8,7 @@ A super easy PHP Framework for web development! ## Requirements - - PHP 5.3+ (PHP 7.0+ recommended with OPCache and igbinary extensions) + - PHP 5.4+ (PHP 7.0+ recommended with OPCache and igbinary extensions) - HTTP Web Server (Apache 2.4+ recommended with mod_rewrite) - Some writable directories (like logs and cache) @@ -121,6 +121,7 @@ All routes are a mapping class with extends the primary Controller class. In a s | DIR_TEMPLATE | string | Directory with templates folder | Yes | | DIR_CACHE | string | Directory to storage the generated caches. | Yes | | CACHE_EXPIRE | timestamp | Time in UNIX timestamp format with seconds for valid cache. Default value is 3600. (1 Hour) | +| USE_PHPFASTCACHE | boolean | Enable the Phpfastcache library for cache resources. | | CACHE_DRIVER | string | Cache method for Phpfastcache. Default is file. | | CACHE_SETTINGS | array | Settings for Phpfastcache (https://www.phpfastcache.com). | | DIR_CONFIG | string | Directory with extra configs files | @@ -274,7 +275,9 @@ To get these rows: ### Cache -This framework use the PhpFastCache (https://www.phpfastcache.com) library to provide a most efficient cache system with many possibilities, like Mencache, Redis, APC or a simple file cache. +This framework contains the PhpFastCache (https://www.phpfastcache.com) library to provide a most efficient cache system with many possibilities, like Mencache, Redis, APC or a simple file cache. +To enable this library, define USE_PHPFASTCACHE constant as true. It works only in PHP 7 or newer. +If you don't set USE_PHPFASTCACHE or use an older version of PHP, Phacil automatic set to simple internal file cache system. | Regular drivers | High performances drivers | Development drivers | |---------------------------------|------------------------------------|-------------------------------| @@ -714,7 +717,7 @@ In a sample case, we have this controller: ## Registrations If you need to register a class or other resource to use in your entire application, you can create using the file *registrations.php* in the **system** folder. - Use to specify a `$registry->set('name', $function);` with the function, class or method if you need. After this, just use `$this->name` to access this registry inside a controller or model. + Use to specify a `$this->registry->set('name', $function);` with the function, class or method if you need. After this, just use `$this->name` to access this registry inside a controller or model. #### Sample to register a simple class Declare in /system/registrations.php @@ -723,7 +726,7 @@ In a sample case, we have this controller: // use for register aditionals $criptoClass = new CriptoClass('salt'); - $registry->set('cripto', $criptoClass); + $this->registry->set('cripto', $criptoClass); ``` Using in /controler/demo/sample.php @@ -754,7 +757,7 @@ In a sample case, we have this controller: //see the load database method above for better comprehension } } - new DBne($registry); + new DBne($this->registry); ``` Using in /controller/demo/sample.php diff --git a/composer.json b/composer.json index 4dc5ebf..b99213d 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,6 @@ "vendor-dir": "./system/vendor/" }, "require": { - "php": ">=5.3.0" + "php": ">=5.4.20" } } diff --git a/system/caches/autoload.php b/system/caches/autoload.php index d88d13f..0c14c20 100644 --- a/system/caches/autoload.php +++ b/system/caches/autoload.php @@ -1,109 +1,12 @@ dirCache)) { - mkdir($this->dirCache, 0755, true); - } - $this->expire = (defined('CACHE_EXPIRE')) ? CACHE_EXPIRE : 3600; - - (defined('CACHE_SETTINGS') && is_array(CACHE_SETTINGS)) ? CacheManager::setDefaultConfig(new ConfigurationOption(CACHE_SETTINGS)) : CacheManager::setDefaultConfig(new ConfigurationOption(array('path' => $this->dirCache))); - - $instancias = ((CacheManager::getInstances())); - - if(count($instancias) < 1) - $this->phpfastcache = (defined('CACHE_DRIVER')) ? CacheManager::getInstance(CACHE_DRIVER) : CacheManager::getInstance('files'); - else - $this->phpfastcache = CacheManager::getInstanceById(array_keys($instancias)[0]); - - - //$this->phpfastcache->clear(); - - } - - public function verify($key) - { - - $CachedString = $this->phpfastcache->getItem($key); - - return $CachedString->isHit(); - } - - public function check($key) - { - return $this->verify($key); - } - - public function get($key) - { - - $CachedString = $this->phpfastcache->getItem($key); - - return $CachedString->get(); - - } - - public function set($key, $value, $expire = true) - { - $this->delete($key); - - $CachedString = $this->phpfastcache->getItem($key); - - //$exp = ($expire == true) ? (time() + $this->expire) : 0; - - $CachedString->set($value)->expiresAfter($this->expire);//in seconds, also accepts Datetime - - $save = $this->phpfastcache->save($CachedString); - - - return $save; // Save the cache item just like you do with doctrine and entities - - } - - public function delete($key) - { - - $this->phpfastcache->deleteItem($key); - clearstatcache(); - - } - - public function deleteAll(){ - - return $this->phpfastcache->clear(); - - } - - public function clear() { - return $this->deleteAll(); - } - - public function stats() { - //var_dump($this->phpfastcache->getStats()); - - $obj = new stdClass(); - - $obj->size = $this->phpfastcache->getStats()->getSize(); - $obj->info = $this->phpfastcache->getStats()->getInfo(); - $obj->rawData = $this->phpfastcache->getStats()->getRawData(); - $obj->data = $this->phpfastcache->getStats()->getData(); - - return $obj; - } - -} \ No newline at end of file +/** + * Copyright (c) 2019. ExacTI Technology Solutions + * GPLv3 General License. + * https://exacti.com.br + * Phacil PHP Framework - https://github.com/exacti/phacil-framework + */ + +if(defined('USE_PHPFASTCACHE') && USE_PHPFASTCACHE == true && version_compare(phpversion(), '7.0.0', '>')) + require_once DIR_SYSTEM."caches/phpfastcache.php"; +else + require_once DIR_SYSTEM."caches/caches.php"; \ No newline at end of file diff --git a/system/caches/caches.php b/system/caches/caches.php index 4ee2469..dcc5c40 100644 --- a/system/caches/caches.php +++ b/system/caches/caches.php @@ -102,7 +102,7 @@ final class Caches { $file = ($this->dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); if (file_exists($file)) { - var_dump($file); + //var_dump($file); //$time = substr(strrchr(strstr($files[0], '.', true), '/'), 1); $time = filemtime($file) + $this->expire; @@ -111,7 +111,7 @@ final class Caches { if ($time < time() and $time !== '0') { - var_dump($file); + //var_dump($file); unlink($file); clearstatcache(); return false; @@ -132,7 +132,7 @@ final class Caches { if ($files) { foreach ($files as $file) { //$time = substr(strrchr($file, '.'), 1); - $time = substr(strrchr(strstr($file, '.', true), '/'), 1); + //$time = substr(strrchr(strstr($file, '.', true), '/'), 1); //var_dump(substr(strrchr(strstr($file, '.', true), '/'), 1)); if (file_exists($file)) { diff --git a/system/caches/phpfastcache.php b/system/caches/phpfastcache.php new file mode 100644 index 0000000..d88d13f --- /dev/null +++ b/system/caches/phpfastcache.php @@ -0,0 +1,109 @@ +dirCache)) { + mkdir($this->dirCache, 0755, true); + } + $this->expire = (defined('CACHE_EXPIRE')) ? CACHE_EXPIRE : 3600; + + (defined('CACHE_SETTINGS') && is_array(CACHE_SETTINGS)) ? CacheManager::setDefaultConfig(new ConfigurationOption(CACHE_SETTINGS)) : CacheManager::setDefaultConfig(new ConfigurationOption(array('path' => $this->dirCache))); + + $instancias = ((CacheManager::getInstances())); + + if(count($instancias) < 1) + $this->phpfastcache = (defined('CACHE_DRIVER')) ? CacheManager::getInstance(CACHE_DRIVER) : CacheManager::getInstance('files'); + else + $this->phpfastcache = CacheManager::getInstanceById(array_keys($instancias)[0]); + + + //$this->phpfastcache->clear(); + + } + + public function verify($key) + { + + $CachedString = $this->phpfastcache->getItem($key); + + return $CachedString->isHit(); + } + + public function check($key) + { + return $this->verify($key); + } + + public function get($key) + { + + $CachedString = $this->phpfastcache->getItem($key); + + return $CachedString->get(); + + } + + public function set($key, $value, $expire = true) + { + $this->delete($key); + + $CachedString = $this->phpfastcache->getItem($key); + + //$exp = ($expire == true) ? (time() + $this->expire) : 0; + + $CachedString->set($value)->expiresAfter($this->expire);//in seconds, also accepts Datetime + + $save = $this->phpfastcache->save($CachedString); + + + return $save; // Save the cache item just like you do with doctrine and entities + + } + + public function delete($key) + { + + $this->phpfastcache->deleteItem($key); + clearstatcache(); + + } + + public function deleteAll(){ + + return $this->phpfastcache->clear(); + + } + + public function clear() { + return $this->deleteAll(); + } + + public function stats() { + //var_dump($this->phpfastcache->getStats()); + + $obj = new stdClass(); + + $obj->size = $this->phpfastcache->getStats()->getSize(); + $obj->info = $this->phpfastcache->getStats()->getInfo(); + $obj->rawData = $this->phpfastcache->getStats()->getRawData(); + $obj->data = $this->phpfastcache->getStats()->getData(); + + return $obj; + } + +} \ No newline at end of file diff --git a/system/engine/VERSION b/system/engine/VERSION index d5e98f7..e21e727 100644 --- a/system/engine/VERSION +++ b/system/engine/VERSION @@ -1 +1 @@ -1.3.2 \ No newline at end of file +1.4.0 \ No newline at end of file diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 6cc8b77..00c53f9 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -10,4 +10,4 @@ require_once(__DIR__ . '/registry.php'); require_once(__DIR__ . '/document.php'); require_once(__DIR__ . '/response.php'); require_once(__DIR__ . '/classes.php'); -require_once(__DIR__ . '/caches.php'); \ No newline at end of file +//require_once(__DIR__ . '/caches.php'); \ No newline at end of file diff --git a/system/engine/caches.php b/system/engine/caches.php deleted file mode 100644 index 1b7a279..0000000 --- a/system/engine/caches.php +++ /dev/null @@ -1,3 +0,0 @@ -key = $this->hash($key); - - if(function_exists('openssl_encrypt')) { - $this->method = 'openssl'; - $this->cipher = $opensslCipher; - } else { - $this->method = 'base64'; - } - - } - - public function hash($value) { - return hash('sha256', $value, true); - } - - public function encrypt ($value, $key = NULL) { - $this->key = ($key != NULL) ? $key : $this->key; - - if($this->method == 'openssl') { - return $this->opensslEncrypt($value); - } else { - return $this->base64Encrypt($value); - } - } - - public function decrypt ($value, $key = NULL) { - $this->key = ($key != NULL) ? $key : $this->key; - - if($this->method == 'openssl') { - return $this->opensslDecrypt($value); - } else { - return $this->base64Decrypt($value); - } - } - - function base64Encrypt($value) { - if (!$this->key) { - return $value; - } - - $output = ''; - - for ($i = 0; $i < strlen($value); $i++) { - $char = substr($value, $i, 1); - $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1); - $char = chr(ord($char) + ord($keychar)); - - $output .= $char; - } - - return base64_encode($output); - } - - function base64Decrypt($value) { - if (!$this->key) { - return $value; - } - - $output = ''; - - $value = base64_decode($value); - - for ($i = 0; $i < strlen($value); $i++) { - $char = substr($value, $i, 1); - $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1); - $char = chr(ord($char) - ord($keychar)); - - $output .= $char; - } - - return $output; - } - - private function opensslEncrypt ($value) { - - $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipher)); - - $ciphertext_raw = strtr(base64_encode(openssl_encrypt($value, $this->cipher, $this->hash( $this->key), 0, $iv)), '+/=', '-_,'); - - //$hmac = hash_hmac('sha256', $ciphertext_raw, $this->key, true); - - $output = $this->base64Encrypt( $iv.$ciphertext_raw ); - - return $output; - - } - - private function opensslDecrypt ($value) { - - $c = $this->base64Decrypt($value); - $ivlen = openssl_cipher_iv_length($this->cipher); - $iv = substr($c, 0, $ivlen); - //$hmac = substr($c, $ivlen, $sha2len=32); - $ciphertext_raw = substr($c, $ivlen); - - - $output = trim(openssl_decrypt(base64_decode(strtr($ciphertext_raw, '-_,', '+/=')), $this->cipher, $this->hash($this->key), 0, $iv)); - - return $output; - } + private $key; + private $method; + private $cipher; + + function __construct($key, $opensslCipher = 'aes-128-cbc') { + $this->key = $this->hash($key); + + if(function_exists('openssl_encrypt')) { + $this->method = 'openssl'; + $this->cipher = $opensslCipher; + } else { + $this->method = 'base64'; + } + + } + + public function hash($value) { + return hash('sha256', $value, true); + } + + public function encrypt ($value, $key = NULL) { + $this->key = ($key != NULL) ? $key : $this->key; + + if($this->method == 'openssl') { + return $this->opensslEncrypt($value); + } else { + return $this->base64Encrypt($value); + } + } + + public function decrypt ($value, $key = NULL) { + $this->key = ($key != NULL) ? $key : $this->key; + + if($this->method == 'openssl') { + return $this->opensslDecrypt($value); + } else { + return $this->base64Decrypt($value); + } + } + + function base64Encrypt($value) { + if (!$this->key) { + return $value; + } + + $output = ''; + + for ($i = 0; $i < strlen($value); $i++) { + $char = substr($value, $i, 1); + $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1); + $char = chr(ord($char) + ord($keychar)); + + $output .= $char; + } + + return base64_encode($output); + } + + function base64Decrypt($value) { + if (!$this->key) { + return $value; + } + + $output = ''; + + $value = base64_decode($value); + + for ($i = 0; $i < strlen($value); $i++) { + $char = substr($value, $i, 1); + $keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1); + $char = chr(ord($char) - ord($keychar)); + + $output .= $char; + } + + return $output; + } + + private function opensslEncrypt ($value) { + + $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipher)); + + $ciphertext_raw = strtr(base64_encode(openssl_encrypt($value, $this->cipher, $this->hash( $this->key), 0, $iv)), '+/=', '-_,'); + + //$hmac = hash_hmac('sha256', $ciphertext_raw, $this->key, true); + + $output = strtr($this->base64Encrypt( $iv.$ciphertext_raw ), '+/=', '-_,'); + + return $output; + + } + + private function opensslDecrypt ($value) { + + $c = $this->base64Decrypt(strtr($value, '-_,', '+/=')); + $ivlen = openssl_cipher_iv_length($this->cipher); + $iv = substr($c, 0, $ivlen); + //$hmac = substr($c, $ivlen, $sha2len=32); + $ciphertext_raw = substr($c, $ivlen); + + + $output = trim(openssl_decrypt(base64_decode(strtr($ciphertext_raw, '-_,', '+/=')), $this->cipher, $this->hash($this->key), 0, $iv)); + + return $output; + } } -?> \ No newline at end of file diff --git a/system/system.php b/system/system.php index 7cb7b16..a8f1b25 100644 --- a/system/system.php +++ b/system/system.php @@ -7,104 +7,116 @@ */ class startEngineExacTI { - public $constants; - public $userConstants; - public $phpversion; - protected $includes; - protected $dirs; - - public function __construct () { - $this->constants = get_defined_constants(true); - $this->userConstants = $this->constants['user']; - $this->includes = get_included_files(); - - // Check Version - $this->phpversion = $this->checkPHPversion(); - - //Check Config Load - $loadConfig = $this->checkConfigFile(); - - if($loadConfig) { - $this->defineAuxConstants(); - } - - if(defined('DEBUG') && DEBUG == true) { - error_reporting(E_ALL); - ini_set('display_errors', 1); - } - - $this->loadengine(); - } - - private function checkPHPversion() { - if (version_compare(phpversion(), '5.3.0', '>') == false) { - exit('PHP 5.3+ Required'); - } else { - return phpversion(); - } - } - - private function checkConfigFile() { - - if (!$this->checkConstantsRequired()) { - try { - $baseDir = str_replace('system', '', __DIR__); - include_once($baseDir."config.php"); - - if (!$this->checkConstantsRequired()) { - throw new \Exception("Can't load minimun config constants, please check your config file!"); - } - - } catch (Exception $e) { - exit($e->getMessage()); - } - - } else { - return true; - } - - } - - private function checkConstantsRequired () { - if (!defined('DIR_APPLICATION') || !defined('DIR_SYSTEM') || !defined('DIR_PUBLIC') || !defined('DIR_TEMPLATE') || !defined('USE_DB_CONFIG')) { - return(false); - } else { - return(true); - } - } - - private function defineAuxConstants () { - (defined('HTTP_URL')) ? define('HTTP_SERVER', HTTP_URL) : ''; - (defined('HTTPS_URL')) ? define('HTTPS_SERVER', HTTPS_URL) : ''; - } - - private function loadengine () { - $this->dirs = glob(DIR_SYSTEM.'*/autoload.php', GLOB_BRACE); - foreach($this->dirs as $key => $value) { - if($value != ""){ - 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()); - } - - } - } - } - - public function setTimezone($utc) { - - try { + public $constants; + public $userConstants; + public $phpversion; + protected $includes; + protected $dirs; + public $registry; + + public function __construct () { + $this->constants = get_defined_constants(true); + $this->userConstants = $this->constants['user']; + $this->includes = get_included_files(); + + // Check Version + $this->phpversion = $this->checkPHPversion(); + + //Check Config Load + $loadConfig = $this->checkConfigFile(); + + if($loadConfig) { + $this->defineAuxConstants(); + } + + if(defined('DEBUG') && DEBUG == true) { + error_reporting(E_ALL); + ini_set('display_errors', 1); + } + + $this->loadengine(); + + // Registry + $this->registry = new Registry(); + } + + public function __get($key) { + return $this->registry->get($key); + } + + public function __set($key, $value) { + $this->registry->set($key, $value); + } + + private function checkPHPversion() { + if (version_compare(phpversion(), '5.4.0', '>') == false) { + exit('PHP 5.4+ Required'); + } else { + return phpversion(); + } + } + + private function checkConfigFile() { + + if (!$this->checkConstantsRequired()) { + try { + $baseDir = str_replace('system', '', __DIR__); + include_once($baseDir."config.php"); + + if (!$this->checkConstantsRequired()) { + throw new \Exception("Can't load minimun config constants, please check your config file!"); + } + + } catch (Exception $e) { + exit($e->getMessage()); + } + + } else { + return true; + } + + } + + private function checkConstantsRequired () { + if (!defined('DIR_APPLICATION') || !defined('DIR_SYSTEM') || !defined('DIR_PUBLIC') || !defined('DIR_TEMPLATE') || !defined('USE_DB_CONFIG')) { + return(false); + } else { + return(true); + } + } + + private function defineAuxConstants () { + (defined('HTTP_URL')) ? define('HTTP_SERVER', HTTP_URL) : ''; + (defined('HTTPS_URL')) ? define('HTTPS_SERVER', HTTPS_URL) : ''; + } + + private function loadengine () { + $this->dirs = glob(DIR_SYSTEM.'*/autoload.php', GLOB_BRACE); + foreach($this->dirs as $key => $value) { + if($value != ""){ + 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()); + } + + } + } + } + + public function setTimezone($utc) { + + try { $tzc = @date_default_timezone_set($utc); if (!$tzc){ throw new \ErrorException($utc. " not found in PHP Compiler."); } } catch (\ErrorException $e) { - $trace = ($e->getTrace()); + $trace = ($e->getTrace()); echo PHP_EOL.'Timezone Error: ', $e->getMessage() ." on ". $trace[0]['file'] ." in line ". $trace[0]['line'].".", PHP_EOL; } @@ -120,50 +132,51 @@ class startEngineExacTI { } public function version() { - return file_get_contents(DIR_SYSTEM."engine/VERSION"); + return file_get_contents(DIR_SYSTEM."engine/VERSION"); } public function extraRegistrations() { + if(file_exists(DIR_SYSTEM."registrations.php")) include(DIR_SYSTEM."registrations.php"); } - + } $engine = new startEngineExacTI(); // Registry -$registry = new Registry(); -$registry->set('engine', $engine); +//$registry = new Registry(); +$engine->registry->set('engine', $engine); // Loader -$loader = new Loader($registry); -$registry->set('load', $loader); +$loader = new Loader($engine->registry); +$engine->registry->set('load', $loader); // Config $config = new Config(); -$registry->set('config', $config); +$engine->registry->set('config', $config); -$registry->set('db', $db); +$engine->registry->set('db', $db); // Settings if(!empty($configs)){ - foreach ($configs as $key => $confValue) { - $config->set($key, $confValue); - } + foreach ($configs as $key => $confValue) { + $config->set($key, $confValue); + } } if(USE_DB_CONFIG === true) { $query = (defined('CUSTOM_DB_CONFIG')) ? $db->query(CUSTOM_DB_CONFIG) : $db->query("SELECT * FROM settings ORDER BY setting_id ASC"); - foreach ($query->rows as $setting) { - if (!$setting['serialized']) { - $config->set($setting['key'], $setting['value']); - } else { - $config->set($setting['key'], unserialize($setting['value'])); - } - } + foreach ($query->rows as $setting) { + if (!$setting['serialized']) { + $config->set($setting['key'], $setting['value']); + } else { + $config->set($setting['key'], unserialize($setting['value'])); + } + } } @@ -177,113 +190,113 @@ if($config->get('date_timezone')){ // Site Title if($config->get('PatternSiteTitle') == true) { - define('PATTERSITETITLE', $config->get('PatternSiteTitle')); + define('PATTERSITETITLE', $config->get('PatternSiteTitle')); } else { - define('PATTERSITETITLE', false); + define('PATTERSITETITLE', false); } // Url -$url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') : $config->get('config_url')); -$registry->set('url', $url); +$url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') : $config->get('config_url')); +$engine->registry->set('url', $url); -// Log +// Log if(!$config->get('config_error_filename')){ - $config->set('config_error_filename', 'error.log'); + $config->set('config_error_filename', 'error.log'); } $log = new Log($config->get('config_error_filename')); -$registry->set('log', $log); +$engine->registry->set('log', $log); function error_handler($errno, $errstr, $errfile, $errline) { - global $log, $config; - - switch ($errno) { - case E_NOTICE: - case E_USER_NOTICE: - $error = 'Notice'; - break; - case E_WARNING: - case E_USER_WARNING: - $error = 'Warning'; - break; - case E_ERROR: - case E_USER_ERROR: - $error = 'Fatal Error'; - break; - default: - $error = 'Unknown'; - break; - } - - if ($config->get('config_error_display')) { - echo '' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline . ''; - } - - if ($config->get('config_error_log')) { - $log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline); - } - - return true; + global $log, $config; + + switch ($errno) { + case E_NOTICE: + case E_USER_NOTICE: + $error = 'Notice'; + break; + case E_WARNING: + case E_USER_WARNING: + $error = 'Warning'; + break; + case E_ERROR: + case E_USER_ERROR: + $error = 'Fatal Error'; + break; + default: + $error = 'Unknown'; + break; + } + + if ($config->get('config_error_display')) { + echo '' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline . ''; + } + + if ($config->get('config_error_log')) { + $log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline); + } + + return true; } - + // Error Handler set_error_handler('error_handler'); //Caches $caches = new Caches(); -$registry->set('cache', $caches); +$engine->registry->set('cache', $caches); // Request $request = new Request(); -$registry->set('request', $request); +$engine->registry->set('request', $request); // Response $response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $response->setCompression($config->get('config_compression')); -$registry->set('response', $response); +$engine->registry->set('response', $response); // Session $session = new Session(); -$registry->set('session', $session); +$engine->registry->set('session', $session); // Translate $translate = new Translate(); -$registry->set('translate', $translate); +$engine->registry->set('translate', $translate); // E-Mail Config $mail = new Mail(); $mail->protocol = $config->get('config_mail_protocol'); if($config->get('config_mail_protocol') == 'smtp'){ - $mail->parameter = $config->get('config_mail_parameter'); - $mail->hostname = $config->get('config_smtp_host'); - $mail->username = $config->get('config_smtp_username'); - $mail->password = $config->get('config_smtp_password'); - $mail->port = $config->get('config_smtp_port'); - $mail->timeout = $config->get('config_smtp_timeout'); + $mail->parameter = $config->get('config_mail_parameter'); + $mail->hostname = $config->get('config_smtp_host'); + $mail->username = $config->get('config_smtp_username'); + $mail->password = $config->get('config_smtp_password'); + $mail->port = $config->get('config_smtp_port'); + $mail->timeout = $config->get('config_smtp_timeout'); } -$registry->set('mail', $mail); - +$engine->registry->set('mail', $mail); + // Document $document = new Document(); -$registry->set('document', $document); +$engine->registry->set('document', $document); // Custom registrations $engine->extraRegistrations(); -// Front Controller -$controller = new Front($registry); +// Front Controller +$controller = new Front($engine->registry); // SEO URL's -$controller->addPreAction(new ActionSystem('url/seo_url')); - +$controller->addPreAction(new ActionSystem('url/seo_url')); + // Router if (isset($request->get['route'])) { - $action = new Action($request->get['route']); + $action = new Action($request->get['route']); } else { $default = (defined('DEFAULT_ROUTE')) ? DEFAULT_ROUTE : 'common/home'; $request->get['route'] = $default; - $action = new Action($default); + $action = new Action($default); } // Dispatch