This repository has been archived by the owner on Jun 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
DevelopmentModeController.php
54 lines (47 loc) · 1.72 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
50
51
52
53
54
<?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";
}
if (!file_exists('config/development.config.php.dist')) {
return "MISSING \"config/development.config.php.dist\". Could not switch to 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";
}
}