From b52984f0a4fc968f3d43053a9446468f47105fd6 Mon Sep 17 00:00:00 2001 From: Fariz Luqman Date: Sun, 10 Jul 2016 20:41:01 +0800 Subject: [PATCH] Release: version 0.1.1 --- .gitignore | 47 ++++++++++++++++++++ src/App.php | 2 +- src/Cache.php | 6 +-- src/Config.php | 109 ++++++++++++++++++++++++++++++++++++++++++++++ src/Database.php | 6 +-- src/Debugger.php | 16 ------- src/Router.php | 4 +- src/Sharer.php | 2 +- src/Singleton.php | 88 +++++++++++++++++++++++++++++++++++++ src/Viewer.php | 2 +- 10 files changed, 255 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100644 src/Config.php create mode 100644 src/Singleton.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd2946a --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ========================= +# Operating System Files +# ========================= + +# OSX +# ========================= + +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/src/App.php b/src/App.php index 40f0740..5b6db88 100644 --- a/src/App.php +++ b/src/App.php @@ -26,7 +26,7 @@ * @author Studio Nexus * @copyright 2016 Studio Nexus * @license MIT - * @version Release: 0.1.0 + * @version Release: 0.1.1 * @link https://www.studionexus.co/php/damnstupidsimple */ namespace Core; diff --git a/src/Cache.php b/src/Cache.php index 139554f..4a60fee 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -26,7 +26,7 @@ * @author Studio Nexus * @copyright 2016 Studio Nexus * @license MIT - * @version Release: 0.1.0 + * @version Release: 0.1.1 * @link https://www.studionexus.co/php/damnstupidsimple */ namespace Core; @@ -73,7 +73,7 @@ class Cache { static function init(){ if(self::$config === null){ - self::$config = require_once(DSS_PATH.'config/cache.php'); + self::$config = Config::get('cache'); } if(self::$config['enabled'] === true){ @@ -98,4 +98,4 @@ static function clean(){ CacheManager::clean(); } -} +} \ No newline at end of file diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..1052545 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,109 @@ + + * @copyright 2016 Studio Nexus + * @license MIT + * @version Release: 0.1.1 + * @link https://www.studionexus.co/php/damnstupidsimple + */ +namespace Core; + +/** + * The Configuration Loader + * ----------------------------------------------------------------------- + * + * The Configuration loader are responsible to read and return the + * configurations in a form of array. + * + * Usage: + * 1. Get the entire configuration from a file: + * $config = Config::get('filename'); + * + * 2. Get specific configuration from a file: + * $config = Config::get('filename', 'configuration_key'); + * + */ +class Config { + + /** + * The array of configuration from config/env.php + * @var array + * @access protected + * @static + */ + protected static $env = null; + + /** + * The array of configuration from files located on config directory + * @var array + * @access protected + * @static + */ + protected static $hive = null; + + /** + * Link a variable or an object to the container + * + * @param string $file the configuration file name (without .php) + * @param string $key the array key + * + * @return array $hive the array of configurations + * + * @static + * @access public + * @since Method available since 0.1.1 + */ + public static function get($file, $key = null){ + if(isset(self::$hive[$file]) === false){ + self::$hive[$file] = include_once(DSS_PATH.'config/'.$file.'.php'); + } + + if($key === null){ + return self::$hive[$file]; + }else{ + return self::$hive[$file][$key]; + } + } + + /** + * Reads the configuration file (config/env.php) and include each of the + * variables (retrieved in a form of associative array) to the Environment + * Variable. Also store the configurations into static variable $env + * + * @static + * @access public + * @since Method available since Release 0.1.1 + */ + public static function setEnv(){ + if(self::$env === null){ + self::$env = require_once(DSS_PATH.'config/env.php'); + } + + foreach(self::$env as $v => $a){ + putenv($v.'='.$a); + } + } +} \ No newline at end of file diff --git a/src/Database.php b/src/Database.php index d71a0a2..be0e12c 100644 --- a/src/Database.php +++ b/src/Database.php @@ -26,7 +26,7 @@ * @author Studio Nexus * @copyright 2016 Studio Nexus * @license MIT - * @version Release: 0.1.0 + * @version Release: 0.1.1 * @link https://www.studionexus.co/php/damnstupidsimple */ namespace Core; @@ -55,10 +55,10 @@ class Database extends Capsule{ * @access public * @since Method available since Release 0.1.0 */ - static function connect(){ + public static function connect(){ if(self::$config === null){ - self::$config = include(DSS_PATH.'config/database.php'); + self::$config = Config::get('database'); } if(self::$config['enabled'] === true){ diff --git a/src/Debugger.php b/src/Debugger.php index ef49db6..294974c 100644 --- a/src/Debugger.php +++ b/src/Debugger.php @@ -149,22 +149,6 @@ static function display($name, $message = ''){ self::set_header('500', 'Internal Server Error'); include('errorpage/'. $name .'.php'); } - - /** - * Reads the configuration file (config/env.php) and and include each of the - * variables (retrieved in a form of associative array) to the Environment - * Variable. - * - * @static - * @access public - * @since Method available since Release 0.1.0 - */ - static function init_env(){ - $var=require_once(DSS_PATH.'config/env.php'); - foreach($var as $v => $a){ - putenv($v.'='.$a); - } - } /** * Calculate a precise time difference. diff --git a/src/Router.php b/src/Router.php index 3d3849e..6ebaa4b 100644 --- a/src/Router.php +++ b/src/Router.php @@ -29,7 +29,7 @@ * @copyright 2015 Noah Buscher * @license https://github.com/noahbuscher/Macaw/blob/master/LICENSE.md MIT * @link https://github.com/noahbuscher/Macaw - * @version Release: 0.1.0 + * @version Release: 0.1.1 */ namespace Core; @@ -138,7 +138,7 @@ public static function dispatch(){ // Fix multi parameters if(!method_exists($controller, $segments[1])) { //"controller and action not found" - Debugger::report(500); + Debugger::report(500); } else { call_user_func_array(array($controller, $segments[1]), $matched); } diff --git a/src/Sharer.php b/src/Sharer.php index 38e0c40..0d2bbf9 100644 --- a/src/Sharer.php +++ b/src/Sharer.php @@ -26,7 +26,7 @@ * @author Studio Nexus * @copyright 2016 Studio Nexus * @license MIT - * @version Release: 0.1.0 + * @version Release: 0.1.1 * @link https://www.studionexus.co/php/damnstupidsimple */ namespace Core; diff --git a/src/Singleton.php b/src/Singleton.php new file mode 100644 index 0000000..b27dfcc --- /dev/null +++ b/src/Singleton.php @@ -0,0 +1,88 @@ + + * @copyright 2016 Studio Nexus + * @license MIT + * @version Release: 0.1.1 + * @link https://www.studionexus.co/php/damnstupidsimple + */ +namespace Core; + +/** + * The Singleton + * ----------------------------------------------------------------------- + * + * Simply extends this Singleton class if you wish to use the Singleton + * pattern of programming in your project + * + */ +class Singleton { + private static $instances = array(); + + /** + * Constructor method + * + * @access protected + * @since Method available since Release 0.1.1 + */ + protected function __construct() { + // + } + + /** + * Avoid cloning + * + * @access protected + * @since Method available since Release 0.1.1 + */ + protected function __clone() { + // + } + + /** + * Avoid unserialization + * + * @access public + * @since Method available since Release 0.1.1 + */ + public function __wakeup(){ + throw new Exception("Cannot unserialize singleton"); + } + + /** + * Get the instance of desired class + * + * @access public + * @since Method available since Release 0.1.1 + */ + public static function getInstance(){ + $class = get_called_class(); // late-static-bound class name + if (!isset(self::$instances[$class])) { + self::$instances[$class] = new static; + } + return self::$instances[$class]; + } +} \ No newline at end of file diff --git a/src/Viewer.php b/src/Viewer.php index e31aaf8..80bf6bf 100644 --- a/src/Viewer.php +++ b/src/Viewer.php @@ -26,7 +26,7 @@ * @author Studio Nexus * @copyright 2016 Studio Nexus * @license MIT - * @version Release: 0.1.0 + * @version Release: 0.1.1 * @link https://www.studionexus.co/php/damnstupidsimple */ namespace Core;