forked from 19FT/NFDevelopmentMode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DevelopmentModeController.php
49 lines (44 loc) · 1.52 KB
/
DevelopmentModeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2013 Zend Technologies USA Inc. (http://www.zend.com)
*/
namespace NFDevelopmentMode;
use Zend\Console\Request as ConsoleRequest;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Controller\AbstractActionController;
class DevelopmentModeController extends AbstractActionController
{
public function setEventManager(EventManagerInterface $events)
{
parent::setEventManager($events);
$events->attach('dispatch', function($e) {
$request = $e->getRequest();
if (!$request instanceof ConsoleRequest) {
throw new \RuntimeException(sprintf(
'%s can only be executed in a console environment',
__CLASS__
));
}
}, 100);
return $this;
}
public function enableAction()
{
if (file_exists('config/development.config.php')) {
// nothing to do
return "Already in development mode!\n";
}
copy('config/development.config.php.dist', 'config/development.config.php');
return "You are now in development mode.\n";
}
public function disableAction()
{
if (!file_exists('config/development.config.php')) {
// nothing to do
return "Development mode was already disabled.\n";
}
unlink('config/development.config.php');
return "Development mode is now disabled.\n";
}
}