From 600874563470ac63172de5da4248bb63b08d9090 Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Mon, 2 Mar 2020 16:19:47 -0800 Subject: [PATCH 1/4] update: 2.x update for PSR-4 and PSR-12 --- LICENSE | 2 +- README.md | 8 +++--- Timer.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ performance.php | 34 ----------------------- 4 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 Timer.php delete mode 100644 performance.php diff --git a/LICENSE b/LICENSE index ab7d0a0..f04f06a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 sleepy-mustache +Copyright (c) 2020 sleepyMUSTACHE Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 905e300..d74b3ba 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Performance -* Date: April 16, 2014 +* Date: March 2, 2020 * Author: Jaime A. Rodriguez -* Version: 1.0 +* Version: 2.0 * License: http://opensource.org/licenses/MIT -Adds a comment to the end of the source code telling the amount of memory used and total run time. - +Adds a comment to the end of the source code telling the amount of memory used and +total run time. ## Usage diff --git a/Timer.php b/Timer.php new file mode 100644 index 0000000..8b87ec3 --- /dev/null +++ b/Timer.php @@ -0,0 +1,74 @@ + + * @license https://opensource.org/licenses/MIT MIT + * @version GIT: 1.0.0 + * @link http://sleepymustache.com + */ + +namespace Module\Perforance; + +use Sleepy\Core\Hook; +use Sleepy\Core\Module; + +/** + * Timer Module + * + * @category Performance + * @package Module/Performance + * @author Jaime Rodriguez + * @license https://opensource.org/licenses/MIT MIT + * @link http://sleepymustache.com + */ +class Timer extends Module +{ + + public $hooks = [ + 'timer_preprocess' => 'setup', + 'sleepy_preprocess' => 'startTimer', + 'sleepy_postprocess' => 'stopTimer' + ]; + + /** + * Setup the Environment settings + * + * @return void + */ + public function setup() + { + $this->environments['stage'] = false; + $this->environments['live'] = false; + } + + /** + * Starts the timer when the framework loads. + * + * @return void + */ + public function startTimer() + { + $this->startTime = microtime(true); + } + + /** + * When everything is done, append the time and memory usage to the file + * + * @return void + */ + public function stopTimer() + { + $this->stopTimer = microtime(true) - $this->startTime; + echo "\n"; + } +} + +Hook::register(new Timer()); diff --git a/performance.php b/performance.php deleted file mode 100644 index 718c8b3..0000000 --- a/performance.php +++ /dev/null @@ -1,34 +0,0 @@ -"; -} - -if (\Sleepy\SM::isDev()) { - \Sleepy\Hook::doAction('sleepy_preprocess', '\Module\Performance\start_timer'); - \Sleepy\Hook::doAction('sleepy_postprocess', '\Module\Performance\stop_timer'); -} - - From 7d39a24fbdb5717f3e71e66112ed0e4e2918a21a Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Thu, 30 Jul 2020 21:35:16 -0700 Subject: [PATCH 2/4] bugfix: namespace spelling --- Timer.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Timer.php b/Timer.php index 8b87ec3..bbc7452 100644 --- a/Timer.php +++ b/Timer.php @@ -13,7 +13,7 @@ * @link http://sleepymustache.com */ -namespace Module\Perforance; +namespace Module\Performance; use Sleepy\Core\Hook; use Sleepy\Core\Module; @@ -29,7 +29,9 @@ */ class Timer extends Module { - + /** + * Define the hook points + */ public $hooks = [ 'timer_preprocess' => 'setup', 'sleepy_preprocess' => 'startTimer', @@ -43,6 +45,7 @@ class Timer extends Module */ public function setup() { + // Disable this module for stage and live $this->environments['stage'] = false; $this->environments['live'] = false; } @@ -68,7 +71,7 @@ public function stopTimer() echo "\n"; - } + } } Hook::register(new Timer()); From 924cf1058faebd6d5c630b5dfabcb0be029b304f Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Fri, 31 Jul 2020 02:52:40 -0700 Subject: [PATCH 3/4] bugfix: typo --- Timer.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Timer.php b/Timer.php index bbc7452..a0b1d80 100644 --- a/Timer.php +++ b/Timer.php @@ -33,21 +33,16 @@ class Timer extends Module * Define the hook points */ public $hooks = [ - 'timer_preprocess' => 'setup', 'sleepy_preprocess' => 'startTimer', 'sleepy_postprocess' => 'stopTimer' ]; - /** - * Setup the Environment settings - * - * @return void - */ - public function setup() - { - // Disable this module for stage and live + public function __construct() { + $this->environments['dev'] = true; $this->environments['stage'] = false; $this->environments['live'] = false; + + parent::__construct(); } /** From a33f2a29deb2d54a1b32f81cfc88792622e3c5f9 Mon Sep 17 00:00:00 2001 From: Jaime Rodriguez Date: Mon, 28 Sep 2020 23:42:52 -0700 Subject: [PATCH 4/4] bugfix: typo --- Timer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Timer.php b/Timer.php index a0b1d80..1463dd9 100644 --- a/Timer.php +++ b/Timer.php @@ -1,6 +1,6 @@ environments['stage'] = false; $this->environments['live'] = false; + // The parent contructor must be called parent::__construct(); }