1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Bldr.io |
5
|
|
|
* |
6
|
|
|
* (c) Aaron Scherer <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bldr\Block\Miscellaneous\Task; |
13
|
|
|
|
14
|
|
|
use Bldr\Block\Core\Task\AbstractTask; |
15
|
|
|
use Bldr\Block\Miscellaneous\Service\EnvironmentVariableRepository; |
16
|
|
|
use Bldr\Exception\TaskRuntimeException; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Luis Cordova <[email protected]> |
21
|
|
|
* @author Raul Rodriguez <[email protected]> |
22
|
|
|
* @author Aaron Scherer <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ExportTask extends AbstractTask |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @type EnvironmentVariableRepository |
28
|
|
|
*/ |
29
|
|
|
protected $environmentVariableRepository; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param EnvironmentVariableRepository $environmentVariableRepository |
33
|
|
|
*/ |
34
|
|
|
public function __construct(EnvironmentVariableRepository $environmentVariableRepository) |
35
|
|
|
{ |
36
|
|
|
$this->environmentVariableRepository = $environmentVariableRepository; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
*/ |
42
|
|
|
public function configure() |
43
|
|
|
{ |
44
|
|
|
$this->setName('export') |
45
|
|
|
->setDescription('Exports an environmental variable within the context of the bldr task run.') |
46
|
|
|
->addParameter('arguments', true, 'Arguments to run on the export', []) |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
|
|
public function run(OutputInterface $output) |
54
|
|
|
{ |
55
|
|
|
foreach ($this->getParameter('arguments') as $argument) { |
|
|
|
|
56
|
|
|
if (2 !== count(explode('=', $argument))) { |
57
|
|
|
throw new TaskRuntimeException( |
58
|
|
|
$this->getName(), |
59
|
|
|
'Each argument needs to follow the pattern e.g. SYMFONY_ENV=prod' |
60
|
|
|
); |
61
|
|
|
}; |
62
|
|
|
$this->environmentVariableRepository->addEnvironmentVariable($argument); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.