1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command; |
4
|
|
|
|
5
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
6
|
|
|
use RuntimeException; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use N98\Util\OperatingSystem; |
11
|
|
|
use N98\Util\Exec; |
12
|
|
|
|
13
|
|
|
class OpenBrowserCommand extends AbstractMagentoCommand |
14
|
|
|
{ |
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
|
|
->setName('open-browser') |
19
|
|
|
->addArgument('store', InputArgument::OPTIONAL, 'Store code or ID') |
20
|
|
|
->setDescription('Open current project in browser <comment>(experimental)</comment>') |
21
|
|
|
; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return bool |
26
|
|
|
*/ |
27
|
|
|
public function isEnabled() |
28
|
|
|
{ |
29
|
|
|
return Exec::allowed(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param InputInterface $input |
34
|
|
|
* @param OutputInterface $output |
35
|
|
|
* @throws RuntimeException |
36
|
|
|
* @return int|void |
37
|
|
|
*/ |
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
39
|
|
|
{ |
40
|
|
|
$opener = ''; |
41
|
|
|
if (OperatingSystem::isMacOs()) { |
42
|
|
|
$opener = 'open'; |
43
|
|
|
} elseif (OperatingSystem::isWindows()) { |
44
|
|
|
$opener = 'start'; |
45
|
|
|
} else { |
46
|
|
|
// Linux |
47
|
|
|
if (exec('which xde-open')) { |
48
|
|
|
$opener = 'xdg-open'; |
49
|
|
|
} elseif (exec('which gnome-open')) { |
50
|
|
|
$opener = 'gnome-open'; |
51
|
|
|
} elseif (exec('which kde-open')) { |
52
|
|
|
$opener = 'kde-open'; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (empty($opener)) { |
57
|
|
|
throw new RuntimeException('No opener command like xde-open, gnome-open, kde-open was found.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->detectMagento($output); |
61
|
|
|
if ($this->initMagento($output)) { |
|
|
|
|
62
|
|
|
$store = $this->getHelperSet()->get('parameter')->askStore($input, $output, 'store', true); |
63
|
|
|
if ($store->getId() == \Mage_Core_Model_App::ADMIN_STORE_ID) { |
64
|
|
|
$adminFrontName = (string) \Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'); |
65
|
|
|
$url = rtrim($store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_WEB), '/') . '/' . $adminFrontName; |
66
|
|
|
} else { |
67
|
|
|
$url = $store->getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_LINK) . '?___store=' . $store->getCode(); |
68
|
|
|
} |
69
|
|
|
$output->writeln('Opening URL <comment>' . $url . '</comment> in browser'); |
70
|
|
|
Exec::run(escapeshellcmd($opener . ' ' . $url)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: