|
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\Filesystem\Task; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Aaron Scherer <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class DumpTask extends FilesystemTask |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritDoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->setName('dump') |
|
27
|
|
|
->setDescription('Dumps the `content` into the given file') |
|
28
|
|
|
->addParameter('file', true, 'File to dump content to') |
|
29
|
|
|
->addParameter('append', true, 'If true, will append to the given file.', false) |
|
30
|
|
|
->addParameter('character', true, 'If append is true, character to use to append.', "\n") |
|
31
|
|
|
->addParameter('content', true, 'Content to dump to file') |
|
32
|
|
|
; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function run(OutputInterface $output) |
|
39
|
|
|
{ |
|
40
|
|
|
$file = $this->getParameter('file'); |
|
41
|
|
|
if (strpos($file, '/') !== 0) { |
|
42
|
|
|
$file = getcwd().'/'.ltrim($file, '/'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$content = $this->getParameter('content'); |
|
46
|
|
|
if ($this->getParameter('append')) { |
|
47
|
|
|
$content = file_get_contents($file).$this->getParameter('character').$content; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->fileSystem->dumpFile($file, $content); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.