Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#266 - Add warning that displayes every 5 minutes about dev mode
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
|
||
namespace eXpansion\Framework\Core\Plugins; | ||
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer; | ||
use eXpansion\Framework\Core\Helpers\ChatNotification; | ||
use eXpansion\Framework\Core\Services\Console; | ||
|
||
|
||
/** | ||
* Class DevModeNotifier | ||
* | ||
* @package eXpansion\Framework\Core\Plugins; | ||
* @author oliver de Cramer <oliverde8@gmail.com> | ||
*/ | ||
class DevModeNotifier implements ListenerInterfaceExpTimer | ||
{ | ||
/** @var ChatNotification */ | ||
protected $chatNotification; | ||
|
||
/** @var Console */ | ||
protected $console; | ||
|
||
/** @var int How often notificaiton needs to be displayed */ | ||
protected $interval = 300; | ||
|
||
/** @var int last time it was displayed. */ | ||
protected $lastDisplayTime; | ||
|
||
/** | ||
* DevModeNotifier constructor. | ||
* | ||
* @param ChatNotification $chatNotification | ||
* @param Console $console | ||
*/ | ||
public function __construct(ChatNotification $chatNotification, Console $console) | ||
{ | ||
$this->chatNotification = $chatNotification; | ||
$this->console = $console; | ||
|
||
// Display once 30 seconds after start. | ||
$this->lastDisplayTime = time() - $this->interval + 10; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function onPreLoop() | ||
{ | ||
// nothing | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function onPostLoop() | ||
{ | ||
// nothing | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function onEverySecond() | ||
{ | ||
if (time() > $this->lastDisplayTime + $this->interval) { | ||
$this->lastDisplayTime = time(); | ||
|
||
$this->console->getSfStyleOutput()->warning( | ||
[ | ||
"!! eXpansion is running in dev mode !!", | ||
"In dev mode eXpansion is not stable and will leak memory which will cause crash.", | ||
"This is normal behaviour. Please use prod mode. ", | ||
"", | ||
"If you are currently developing please ignore this message.", | ||
] | ||
); | ||
$this->chatNotification->sendMessage("{warning} eXpansion is in dev mode. Memory leaks are normal."); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/eXpansion/Framework/Core/Resources/config/plugins_dev.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: true | ||
|
||
# | ||
# Plugin to warn agains dev mode being enabled. | ||
# | ||
eXpansion\Framework\Core\Plugins\DevModeNotifier: | ||
class: 'eXpansion\Framework\Core\Plugins\DevModeNotifier' | ||
tags: | ||
- {name: expansion.plugin, data_provider: exp.timer} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters