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..1463dd9 --- /dev/null +++ b/Timer.php @@ -0,0 +1,73 @@ + + * @license https://opensource.org/licenses/MIT MIT + * @version GIT: 1.0.0 + * @link http://sleepymustache.com + */ + +namespace Module\Performance; + +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 +{ + /** + * Define the hook points + */ + public $hooks = [ + 'sleepy_preprocess' => 'startTimer', + 'sleepy_postprocess' => 'stopTimer' + ]; + + public function __construct() { + $this->environments['dev'] = true; + $this->environments['stage'] = false; + $this->environments['live'] = false; + + // The parent contructor must be called + parent::__construct(); + } + + /** + * 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'); -} - -