-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWslPipeFormatter.php
More file actions
62 lines (54 loc) · 1.78 KB
/
WslPipeFormatter.php
File metadata and controls
62 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types=1);
namespace uuf6429\PhpCsFixerBlockstring\Formatter;
use uuf6429\PhpCsFixerBlockstring\InterpolationCodec\CodecInterface;
use uuf6429\PhpCsFixerBlockstring\LineEndingNormalizer\DefaultNormalizer;
use uuf6429\PhpCsFixerBlockstring\LineEndingNormalizer\NormalizerInterface;
/**
* A formatter making use of Windows Subsystem for Linux (WSL). Of course, you will need to be running on Windows,
* and WSL needs to be enabled and set up. Configuration is otherwise almost identical to {@see CliPipeFormatter}.
*/
class WslPipeFormatter extends CliPipeFormatter
{
/**
* @readonly
* @var 'standard'|'login'|'none'
*/
private string $shellType;
/**
* @param 'standard'|'login'|'none' $shellType
* @param null|bool|NormalizerInterface $lineEndingNormalizer
*/
public function __construct(
$versionValueOrCommand,
array $formatCommand,
?CodecInterface $interpolationCodec = null,
string $shellType = 'login',
$lineEndingNormalizer = true
) {
$this->shellType = $shellType;
if (is_bool($lineEndingNormalizer)) {
trigger_deprecation(
'uuf6429/php-cs-fixer-blockstring',
'1.0.4',
'Passing a bool for argument $lineEndingNormalizer to %s is deprecated',
__METHOD__
);
$lineEndingNormalizer = new DefaultNormalizer(
DefaultNormalizer::LF,
$lineEndingNormalizer ? DefaultNormalizer::STRIP : DefaultNormalizer::NO_CHANGE
);
}
parent::__construct($versionValueOrCommand, $formatCommand, $interpolationCodec, $lineEndingNormalizer);
}
protected function exec(array $spec, ?string $input): string
{
$spec['cmd'] = sprintf(
'wsl --shell-type %s -- %s',
$this->shellType,
is_string($spec['cmd'])
? $spec['cmd']
: implode(' ', array_map('escapeshellarg', $spec['cmd']))
);
return parent::exec($spec, $input);
}
}