From b79002eea17c790b0e02c5be7780f0de7ce18afc Mon Sep 17 00:00:00 2001 From: FlexSuite Date: Sat, 4 Feb 2017 06:41:31 +0800 Subject: [PATCH] Release 0.3.3 - Update README.md - Change PHPDoc - Change the DSS_PATH constant to SS_PATH - Introducing the Request class. Response and Request now separated and support new features --- README.md | 4 +- src/Alias.php | 17 +++--- src/App.php | 16 +++--- src/Cache.php | 16 +++--- src/Config.php | 20 +++---- src/Database.php | 16 +++--- src/Debugger.php | 20 +++---- src/Request.php | 72 +++++++++++++++++++++++++ src/Response.php | 92 +++++++++++++++++++------------- src/Router.php | 14 ++--- src/Service.php | 30 +++++++++++ src/Service/ServiceContainer.php | 9 ++++ src/Sharer.php | 16 +++--- src/Singleton.php | 16 +++--- src/TimeTrackr.php | 31 ++++++++++- src/Viewer.php | 22 ++++---- src/errorpage/style.css | 9 ++++ tests/AppTest.php | 13 ++++- tests/bootstrap.php | 15 ++++-- 19 files changed, 318 insertions(+), 130 deletions(-) create mode 100755 src/Request.php diff --git a/README.md b/README.md index a3ae9ad..eef2d4b 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# damnstupidsimple/core -The core package for Damn Stupid Simple framework. This is a subtree split for [Damn Stupid Simple framework](https://github.com/damnstupidsimple/framework). +# stupidlysimple/core +The core package for StupidlySimple framework. This is a subtree split for [StupidlySimple framework](https://github.com/stupidlysimple/framework). Documentations are available on the main package. diff --git a/src/Alias.php b/src/Alias.php index f45706e..e0c5339 100755 --- a/src/Alias.php +++ b/src/Alias.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ + namespace Core; /** diff --git a/src/App.php b/src/App.php index 68316bd..ec346d8 100755 --- a/src/App.php +++ b/src/App.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; diff --git a/src/Cache.php b/src/Cache.php index bb45498..52dddd9 100755 --- a/src/Cache.php +++ b/src/Cache.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; use phpFastCache\CacheManager as CacheManager; diff --git a/src/Config.php b/src/Config.php index 975c85c..e271d94 100755 --- a/src/Config.php +++ b/src/Config.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; @@ -78,7 +78,7 @@ class Config { */ public static function get($file, $key = null){ if(isset(self::$hive[$file]) === false){ - self::$hive[$file] = include_once(DSS_PATH.'config/'.$file.'.php'); + self::$hive[$file] = include_once(SS_PATH.'config/'.$file.'.php'); } if($key === null){ @@ -99,7 +99,7 @@ public static function get($file, $key = null){ */ public static function setEnv(){ if(self::$env === null){ - self::$env = require_once(DSS_PATH.'config/env.php'); + self::$env = require_once(SS_PATH.'config/env.php'); } foreach(self::$env as $v => $a){ diff --git a/src/Database.php b/src/Database.php index 07d8e44..b34c2e6 100755 --- a/src/Database.php +++ b/src/Database.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; use Illuminate\Database\Capsule\Manager as Capsule; diff --git a/src/Debugger.php b/src/Debugger.php index 612857c..9e3a1bd 100755 --- a/src/Debugger.php +++ b/src/Debugger.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; @@ -187,7 +187,7 @@ static private function microtime_diff($start) * @since Method available since Release 0.1.0 */ static function exec_time(){ - echo ('Request takes '.(self::microtime_diff(DSS_START) * 1000 ) . ' milliseconds'); + echo ('Request takes '.(self::microtime_diff(SS_START) * 1000 ) . ' milliseconds'); } static function startProfiling(){ @@ -215,7 +215,7 @@ static function addProfilingData($point_name = '', $point_type = 'others'){ } static function endProfiling(){ - $timeIncludingAutoloader = self::microtime_diff(DSS_START) * 1000; + $timeIncludingAutoloader = self::microtime_diff(SS_START) * 1000; $timeProfiled = self::microtime_diff(self::$profilerStartTime) * 1000; $timeMinusAutoloader = $timeIncludingAutoloader - $timeProfiled; diff --git a/src/Request.php b/src/Request.php new file mode 100755 index 0000000..60c3182 --- /dev/null +++ b/src/Request.php @@ -0,0 +1,72 @@ + + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ + */ +namespace Core; + +class Request { + + private static $_instance = null; + private $data = []; + + private function __construct(){ + // merge data with get, post and files + $this->data = array_merge($_GET, $_POST, $_FILES); + + // start session to get flash variables + if(!isset($_SESSION)){ + session_start(); + } + // merge data with flash variables + if(isset($_SESSION['ss_flash_variables'])){ + $this->data = array_merge($_SESSION['ss_flash_variables']); + unset($_SESSION['ss_flash_variables']); + } + } + + static function get($key = null){ + if (self::$_instance === null) { + self::$_instance = new self; + } + + return self::$_instance->returnRequest($key); + } + + function returnRequest($key = null){ + if($key !== null){ + if(!isset($this->data[$key])){ + return null; + } + return $this->data[$key]; + }else{ + return $this->data; + } + } +} \ No newline at end of file diff --git a/src/Response.php b/src/Response.php index 755685b..d234bea 100755 --- a/src/Response.php +++ b/src/Response.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.3.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; +use Illuminate\Support\Facades\Session; + class Response { - private static $_instance = null; - private $data = []; + /** + * Hive containing all response values + * @var array + */ + private static $hive = []; - private function __construct(){ - $this->data = array_merge($_GET, $_POST); - } + private static $htmlLocation; + private static $time; + private static $flashVarsTTL = 10; - static function redirect($html_location, $time = 0){ - if(!headers_sent()) - { - header("Location:".$html_location, TRUE, 302); - exit; - } - exit(''); + /** + * Response constructor. + */ + private function __construct() + { + if(!isset($_SESSION)){ + session_start(); + } } - static function get($key = null){ - if (self::$_instance === null) { - self::$_instance = new self; - } - - return self::$_instance->returnResponse($key); + /** + * Redirect to a location + * @param $htmlLocation + * @param int $time + * @return Response + */ + public static function redirect($htmlLocation, $time = 0) + { + self::$htmlLocation = $htmlLocation; + self::$time = $time; + return new self; } - function returnResponse($key = null){ - if($key !== null){ - if(!isset($this->data[$key])){ - return null; - } - return $this->data[$key]; - }else{ - return $this->data; - } - } + // hello? + public function with(array $flashVars) + { + $_SESSION['ss_flash_variables'] = $flashVars; + } + + /** + * We do redirect when the Response object is destroyed. + */ + public function __destruct() + { + if(!headers_sent()) + { + header("Location:".self::$htmlLocation, TRUE, 302); + exit(); + } + // Something has caused our redirect not working properly. Using redirect with meta + exit(''); + } } \ No newline at end of file diff --git a/src/Router.php b/src/Router.php index 4e019d3..607bf39 100755 --- a/src/Router.php +++ b/src/Router.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman * @license MIT - * @version Release: 0.3.2 - * @link https://www.studionexus.co/php/damnstupidsimple + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; diff --git a/src/Service.php b/src/Service.php index b789669..802b357 100644 --- a/src/Service.php +++ b/src/Service.php @@ -1,4 +1,34 @@ + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ + */ namespace Core; /** diff --git a/src/Service/ServiceContainer.php b/src/Service/ServiceContainer.php index dff5cae..efd16b5 100644 --- a/src/Service/ServiceContainer.php +++ b/src/Service/ServiceContainer.php @@ -1,4 +1,13 @@ + * @copyright 2017 Fariz Luqman + * @license MIT + * @link https://stupidlysimple.github.io/ + */ namespace Core\Service; class ServiceContainer { diff --git a/src/Sharer.php b/src/Sharer.php index 355895e..985e0e1 100755 --- a/src/Sharer.php +++ b/src/Sharer.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; diff --git a/src/Singleton.php b/src/Singleton.php index 1e8744b..cc4f358 100755 --- a/src/Singleton.php +++ b/src/Singleton.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.2.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; diff --git a/src/TimeTrackr.php b/src/TimeTrackr.php index 4ba6237..b775c49 100644 --- a/src/TimeTrackr.php +++ b/src/TimeTrackr.php @@ -1,5 +1,34 @@ + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ + */ namespace Core; /** diff --git a/src/Viewer.php b/src/Viewer.php index 9b112b8..d4ce661 100755 --- a/src/Viewer.php +++ b/src/Viewer.php @@ -1,8 +1,8 @@ - * @copyright 2016 Studio Nexus - * @license MIT - * @version Release: 0.3.0 - * @link https://www.studionexus.co/php/damnstupidsimple + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @since 0.3.3 + * @link https://stupidlysimple.github.io/ */ namespace Core; @@ -69,10 +69,10 @@ static function file($file, array &$data = []){ self::render($callingScriptDirectory.'/'.$file, $data); }else if(file_exists($callingScriptDirectory.'/'.$file.'.php')){ self::render($callingScriptDirectory.'/'.$file.'.php', $data); - }else if(file_exists(DSS_PATH.$file)){ + }else if(file_exists(SS_PATH.$file)){ self::render($file, $data); - }else if(file_exists(DSS_PATH.$file.'.php')){ - self::render(DSS_PATH.$file.'.php'); + }else if(file_exists(SS_PATH.$file.'.php')){ + self::render(SS_PATH.$file.'.php', $data); }else{ Debugger::report(404, true); } diff --git a/src/errorpage/style.css b/src/errorpage/style.css index abad92e..b74ca6b 100755 --- a/src/errorpage/style.css +++ b/src/errorpage/style.css @@ -1,3 +1,12 @@ +/** + * StupidlySimple - A PHP Framework For Lazy Developers + * + * @package StupidlySimple + * @author Fariz Luqman + * @copyright 2017 Fariz Luqman + * @license MIT + * @link https://stupidlysimple.github.io/ + */ .dss_main { padding: 18px; width: 100%; diff --git a/tests/AppTest.php b/tests/AppTest.php index 19e2c19..5eba029 100755 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1,4 +1,14 @@ + * @copyright 2017 Fariz Luqman + * @license MIT + * @link https://stupidlysimple.github.io/ + */ + /** * PHP Unit Testing */ @@ -34,5 +44,4 @@ public function testConsumer() func_get_args() ); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c26965b..051bba1 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,16 @@ + * @copyright 2017 Fariz Luqman + * @license MIT + * @link https://stupidlysimple.github.io/ + */ + /** * PHP Unit Testing */ -define('DSS_PATH', realpath(dirname(__FILE__)) .'/../../../../'); -require DSS_PATH . 'vendor/autoload.php'; -?> \ No newline at end of file +define('SS_PATH', realpath(dirname(__FILE__)) .'/../../../../'); +require SS_PATH . 'vendor/autoload.php';