1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Symfony\Component\Console\Application; |
4
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ConsoleController |
8
|
|
|
* The Central Command Access Point and Bootstrapper |
9
|
|
|
*/ |
10
|
|
|
class ConsoleController extends Controller |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private static $allowed_actions = array( |
|
|
|
|
16
|
|
|
'publish' |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Symfony\Component\Console\Application |
21
|
|
|
*/ |
22
|
|
|
protected $application; |
23
|
|
|
|
24
|
|
|
public function index() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
parent::init(); |
|
|
|
|
27
|
|
|
if (!Director::is_cli()) { |
28
|
|
|
$this->httpError(404); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->application = new Application(); |
32
|
|
|
|
33
|
|
|
$this->loadCommands(); |
34
|
|
|
|
35
|
|
|
// remove the framework/cli-script.php argument |
36
|
|
|
array_shift($_SERVER['argv']); |
37
|
|
|
return $this->application->run(new ArgvInput($_SERVER['argv'])); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function publish() |
41
|
|
|
{ |
42
|
|
|
if (Director::is_cli()) { |
43
|
|
|
$this->writeSuperSakeFileToWebRoot(); |
44
|
|
|
$this->writehtaccess(); |
|
|
|
|
45
|
|
|
$this->writewebconfig(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function loadCommands() |
50
|
|
|
{ |
51
|
|
|
//somehow this does not work. |
52
|
|
|
//$commands = ClassInfo::subclassesFor('SilverstripeCommand'); |
|
|
|
|
53
|
|
|
//var_dump($commands);exit(); |
|
|
|
|
54
|
|
|
|
55
|
|
|
// and this is will not load other classes |
56
|
|
|
$commands = ClassInfo::classes_for_folder(BASE_PATH . '/console/'); |
57
|
|
|
|
58
|
|
|
/** @var SilverstripeCommand $command */ |
59
|
|
|
foreach ($commands as $command) { |
60
|
|
|
if (is_subclass_of($command, 'SilverstripeCommand')) { |
61
|
|
|
$this->application->add(new $command()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function writeSuperSakeFileToWebRoot() |
67
|
|
|
{ |
68
|
|
|
file_put_contents( |
69
|
|
|
BASE_PATH . '/supersake', |
70
|
|
|
file_get_contents(BASE_PATH . '/console/publish/supersake') |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* protect the supersake file with htaccess |
76
|
|
|
*/ |
77
|
|
|
protected function writehtaccess() |
78
|
|
|
{ |
79
|
|
|
$content = "# Deny access to supersake |
|
|
|
|
80
|
|
|
<Files supersake> |
81
|
|
|
Order allow,deny |
82
|
|
|
Deny from all |
83
|
|
|
</Files>"; |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* protect the supersake file with web.config |
89
|
|
|
*/ |
90
|
|
|
public function writewebconfig() |
91
|
|
|
{ |
92
|
|
|
//<add fileExtension="supersake" allowed="false"/> |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.