|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Installer\SubCommand; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\SubCommand\AbstractSubCommand; |
|
6
|
|
|
|
|
7
|
|
|
class RewriteHtaccessFile extends AbstractSubCommand |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @return bool |
|
|
|
|
|
|
11
|
|
|
*/ |
|
12
|
|
|
public function execute() |
|
13
|
|
|
{ |
|
14
|
|
|
if ($this->input->getOption('useDefaultConfigParams') !== null |
|
15
|
|
|
|| $this->input->getOption('replaceHtaccessFile') === null |
|
16
|
|
|
) { |
|
17
|
|
|
return; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$this->getCommand()->getApplication()->setAutoExit(false); |
|
21
|
|
|
$dialog = $this->getCommand()->getHelper('dialog'); |
|
22
|
|
|
|
|
23
|
|
|
$replaceHtaccessFile = false; |
|
24
|
|
|
|
|
25
|
|
View Code Duplication |
if ($this->input->hasOption('replaceHtaccessFile')) { |
|
|
|
|
|
|
26
|
|
|
$replaceHtaccessFile = $this->getCommand()->parseBoolOption($this->input->getOption('replaceHtaccessFile')); |
|
27
|
|
|
} elseif ($dialog->askConfirmation( |
|
28
|
|
|
$this->output, |
|
29
|
|
|
'<question>Write BaseURL to .htaccess file?</question> <comment>[n]</comment>: ', |
|
30
|
|
|
false |
|
31
|
|
|
) |
|
32
|
|
|
) { |
|
33
|
|
|
$replaceHtaccessFile = true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (!$replaceHtaccessFile) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$args = $this->config->getArray('installation_args'); |
|
41
|
|
|
$this->replaceHtaccessFile($args['base-url']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $baseUrl |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function replaceHtaccessFile($baseUrl) |
|
48
|
|
|
{ |
|
49
|
|
|
$htaccessFile = $this->config->getString('installationFolder') |
|
50
|
|
|
. DIRECTORY_SEPARATOR |
|
51
|
|
|
. 'pub' |
|
52
|
|
|
. DIRECTORY_SEPARATOR |
|
53
|
|
|
. '.htaccess'; |
|
54
|
|
|
|
|
55
|
|
|
$this->_backupOriginalFile($htaccessFile); |
|
56
|
|
|
$this->_replaceContent($htaccessFile, $baseUrl); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected function _backupOriginalFile($htaccesFile) |
|
60
|
|
|
{ |
|
61
|
|
|
copy( |
|
62
|
|
|
$htaccesFile, |
|
63
|
|
|
$htaccesFile . '.dist' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $htaccessFile |
|
69
|
|
|
* @param string $baseUrl |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function _replaceContent($htaccessFile, $baseUrl) |
|
72
|
|
|
{ |
|
73
|
|
|
$content = file_get_contents($htaccessFile); |
|
74
|
|
|
$content = str_replace('#RewriteBase /magento/', 'RewriteBase ' . parse_url($baseUrl, PHP_URL_PATH), $content); |
|
75
|
|
|
file_put_contents($htaccessFile, $content); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.