From 4b7c4d77504bbe79e0f56fefbff43c2e7e515c8b Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Mon, 2 Mar 2020 15:12:27 -0800 Subject: [PATCH 01/14] update: New structure per PSR-4 autoload --- sleepy.php => bootstrap.php | 0 class.debug.php => core/Debug.php | 0 class.hooks.php => core/Hook.php | 0 class.sm.php => core/SM.php | 0 class.template.php => core/Template.php | 0 class.crud.php => mvc/CRUD.php | 0 class.controller.php => mvc/Controller.php | 0 class.model.php => mvc/Model.php | 0 class.router.php => mvc/Router.php | 0 class.view.php => mvc/View.php | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename sleepy.php => bootstrap.php (100%) rename class.debug.php => core/Debug.php (100%) rename class.hooks.php => core/Hook.php (100%) rename class.sm.php => core/SM.php (100%) rename class.template.php => core/Template.php (100%) rename class.crud.php => mvc/CRUD.php (100%) rename class.controller.php => mvc/Controller.php (100%) rename class.model.php => mvc/Model.php (100%) rename class.router.php => mvc/Router.php (100%) rename class.view.php => mvc/View.php (100%) diff --git a/sleepy.php b/bootstrap.php similarity index 100% rename from sleepy.php rename to bootstrap.php diff --git a/class.debug.php b/core/Debug.php similarity index 100% rename from class.debug.php rename to core/Debug.php diff --git a/class.hooks.php b/core/Hook.php similarity index 100% rename from class.hooks.php rename to core/Hook.php diff --git a/class.sm.php b/core/SM.php similarity index 100% rename from class.sm.php rename to core/SM.php diff --git a/class.template.php b/core/Template.php similarity index 100% rename from class.template.php rename to core/Template.php diff --git a/class.crud.php b/mvc/CRUD.php similarity index 100% rename from class.crud.php rename to mvc/CRUD.php diff --git a/class.controller.php b/mvc/Controller.php similarity index 100% rename from class.controller.php rename to mvc/Controller.php diff --git a/class.model.php b/mvc/Model.php similarity index 100% rename from class.model.php rename to mvc/Model.php diff --git a/class.router.php b/mvc/Router.php similarity index 100% rename from class.router.php rename to mvc/Router.php diff --git a/class.view.php b/mvc/View.php similarity index 100% rename from class.view.php rename to mvc/View.php From 478b9dc56c4fba6ec62b9f2885e58d904c54c30a Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Mon, 2 Mar 2020 15:12:57 -0800 Subject: [PATCH 02/14] update: Update Code per PSR-12 --- bootstrap.php | 55 +-- core/Debug.php | 234 ++++++++---- core/Hook.php | 493 +++++++++++++----------- core/Loader.php | 215 +++++++++++ core/Module.php | 86 +++++ core/SM.php | 285 ++++++++------ core/Template.php | 832 +++++++++++++++++++++------------------- mvc/CRUD.php | 185 +++++---- mvc/Controller.php | 47 ++- mvc/Model.php | 170 +++++++-- mvc/Router.php | 918 +++++++++++++++++++++++++-------------------- mvc/View.php | 81 ++-- settings.php | 173 +++++---- 13 files changed, 2319 insertions(+), 1455 deletions(-) create mode 100644 core/Loader.php create mode 100644 core/Module.php diff --git a/bootstrap.php b/bootstrap.php index 380f791..846c3cd 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,27 +1,40 @@ -* require_once('/app/core/sleepy.php'); -* -* -* ### Changelog -* -* ## Version 1.1 -* * Added documentation -* -* -* @date July 18, 2016 -* @author Jaime A. Rodriguez -* @version 1.1 -* @license http://opensource.org/licenses/MIT -*/ + * Main bootstrap file + * + * ### Usage + * + * + * require_once('/app/core/sleepy.php'); + * + * + * ### Changelog + * + * ### Version 2.0a + * * Converted to PSR-4 + * + * ## Version 1.1 + * * Added documentation + * + * php version 7.0.0 + * + * @category Core + * @package Sleepy + * @author Jaime A. Rodriguez + * @license http://opensource.org/licenses/MIT; MIT + * @link https://sleepymustache.com + */ -require_once('class.sm.php'); +// Get the loader that all other Classes will rely on +require_once $_SERVER['DOCUMENT_ROOT'] . '/app/sleepy/core/Loader.php'; + +use Sleepy\Core\Loader; +use Sleepy\Core\SM; + +Loader::register(); +Loader::addNamespace('Sleepy', $_SERVER['DOCUMENT_ROOT'] . '\app\sleepy'); +Loader::addNamespace('Sleepy\Core', $_SERVER['DOCUMENT_ROOT'] . '\app\sleepy\core'); +Loader::addNamespace('Module', $_SERVER['DOCUMENT_ROOT'] . '\app\sleepy\module'); SM::initialize(); \ No newline at end of file diff --git a/core/Debug.php b/core/Debug.php index a0a2824..8810bb8 100644 --- a/core/Debug.php +++ b/core/Debug.php @@ -1,6 +1,4 @@ - * @version 1.10 - * @license http://opensource.org/licenses/MIT + * php version 7.0.0 + * + * @category Core + * @package Sleepy + * @author Jaime A. Rodriguez + * @license http://opensource.org/licenses/MIT; MIT + * @link https://sleepymustache.com */ -class Debug { +namespace Sleepy\Core; + +/** + * The Debug class + * + * @category Core + * @package Sleepy + * @author Jaime A. Rodriguez + * @license http://opensource.org/licenses/MIT; MIT + * @link https://sleepymustache.com + */ +class Debug +{ /** * The single instance is stored here. * * @var Debug */ - private static $_instance = NULL; + private static $_instance = null; /** * PDO Database object @@ -58,28 +76,28 @@ class Debug { * * @var bool */ - public static $enable_console = false; + public static $enableConsole = false; /** * Enable output to screen * * @var bool */ - public static $enable_show = false; + public static $enableShow = false; /** * Enabled logging to a database * * @var bool */ - public static $enable_log = false; + public static $enableLog = false; /** * Enabled logging via email * * @var bool */ - public static $enable_send = false; + public static $enableSend = false; /** * Email address to send email to. @@ -163,24 +181,36 @@ class Debug { * * @return void */ - private function __clone() {} + private function __clone() + { + } /** * The constructor is private to ensure we only have one instance * * @return void */ - private function __construct() { + private function __construct() + { // Setup email defaults - $server_ip = (isset($_SERVER['SERVER_ADDR'])) ? $_SERVER['SERVER_ADDR'] : ''; - $user_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ''; - $filename = (isset($_SERVER['SCRIPT_FILENAME'])) ? $_SERVER['SCRIPT_FILENAME'] : ''; - $date = date(DATE_ATOM, mktime(date('G'), date('i'), 0, date('m'), date('d'), date('Y'))); + $serverIp = (isset($_SERVER['SERVER_ADDR'])) + ? $_SERVER['SERVER_ADDR'] + : ''; + $userIp = (isset($_SERVER['REMOTE_ADDR'])) + ? $_SERVER['REMOTE_ADDR'] + : ''; + $filename = (isset($_SERVER['SCRIPT_FILENAME'])) + ? $_SERVER['SCRIPT_FILENAME'] + : ''; + $date = date( + DATE_ATOM, + mktime(date('G'), date('i'), 0, date('m'), date('d'), date('Y')) + ); Debug::$emailBuffer = array(); Debug::$emailBuffer[] = "Date: {$date}"; - Debug::$emailBuffer[] = "Server IP: {$server_ip}"; - Debug::$emailBuffer[] = "Client IP: {$user_ip}"; + Debug::$emailBuffer[] = "Server IP: {$serverIp}"; + Debug::$emailBuffer[] = "Client IP: {$userIp}"; Debug::$emailBuffer[] = "Filename: {$filename}"; Debug::$emailBuffer[] = '---'; Debug::$emailTo = EMAIL_TO; @@ -202,18 +232,20 @@ private function __construct() { * * @return void */ - public function __destruct() { - if (self::$enable_send) { + public function __destruct() + { + if (self::$enableSend) { self::sendEmail(); } } /** - * Return instance or create initial instance - * - * @return Debug - */ - private static function _initialize() { + * Return instance or create initial instance + * + * @return Debug + */ + private static function _initialize() + { if (!self::$_instance) { self::$_instance = new Debug(); } @@ -225,18 +257,21 @@ private static function _initialize() { * Displays debug information in JS Console * * @param mixed $var Anything you want to log + * * @return bool - * @todo create a hook so the dev can create custom views when outputting - * debug data. + * + * @todo create a hook so the dev can create custom views when outputting + * debug data. */ - private static function console($var) { + private static function _console($var) + { $output = ''; - if (!self::$enable_console) { + if (!self::$enableConsole) { return false; } - echo '