|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) shopware AG <[email protected]> |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ShopwarePlugins\Connect\Commands; |
|
9
|
|
|
|
|
10
|
|
|
use Shopware\Commands\ShopwareCommand; |
|
11
|
|
|
use Shopware\Components\ConfigWriter; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
16
|
|
|
|
|
17
|
|
|
class ApiEndpointCommand extends ShopwareCommand |
|
18
|
|
|
{ |
|
19
|
|
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
$this |
|
22
|
|
|
->setName('connect:endpoint:set') |
|
23
|
|
|
->setDescription('Set the API endpoint to a custom location') |
|
24
|
|
|
->addArgument( |
|
25
|
|
|
'api-endpoint', |
|
26
|
|
|
InputArgument::REQUIRED, |
|
27
|
|
|
'URL to of the API endpoint.' |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param InputInterface $input |
|
33
|
|
|
* @param OutputInterface $output |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var ConfigWriter $configWriter */ |
|
38
|
|
|
$configWriter = $this->container->get('config_writer'); |
|
39
|
|
|
$symfonyStyle = new SymfonyStyle($input, $output); |
|
40
|
|
|
$apiEndpoint = $input->getArgument('api-endpoint'); |
|
41
|
|
|
|
|
42
|
|
|
$host = parse_url($apiEndpoint, PHP_URL_HOST); |
|
43
|
|
|
if (!$host) { |
|
|
|
|
|
|
44
|
|
|
$host = $apiEndpoint; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$configWriter->save('connectDebugHost', $host); |
|
48
|
|
|
$symfonyStyle->success('Endpoint was updated successfully to ' . $host); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: