-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWslPipeFormatter.php
More file actions
56 lines (49 loc) 路 1.59 KB
/
Copy pathWslPipeFormatter.php
File metadata and controls
56 lines (49 loc) 路 1.59 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
<?php declare(strict_types=1);
namespace uuf6429\PhpCsFixerBlockstring\Formatter;
use uuf6429\PhpCsFixerBlockstring\InterpolationCodec\CodecInterface;
use uuf6429\PhpCsFixerBlockstring\LineEndingNormalizer\DefaultNormalizer;
use uuf6429\PhpCsFixerBlockstring\LineEndingNormalizer\NormalizerInterface;
use uuf6429\PhpCsFixerBlockstring\Process\ProcessFactoryInterface;
/**
* 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
*/
public function __construct(
$versionValueOrCommand,
array $formatCommand,
?CodecInterface $interpolationCodec = null,
string $shellType = 'login',
?NormalizerInterface $lineEndingNormalizer = null,
?ProcessFactoryInterface $processFactory = null
) {
$this->shellType = $shellType;
parent::__construct(
$versionValueOrCommand,
$formatCommand,
$interpolationCodec,
$lineEndingNormalizer ?? new DefaultNormalizer(DefaultNormalizer::LF, DefaultNormalizer::STRIP),
$processFactory
);
}
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);
}
}