-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerImage.php
34 lines (28 loc) · 907 Bytes
/
DockerImage.php
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
<?php
namespace Aboks\PhpSrcDevtools;
use Symfony\Component\Process\Process;
class DockerImage
{
public function createProcess($subcommand, $arguments = []): Process
{
$cwd = getcwd();
if (DIRECTORY_SEPARATOR === '\\') {
$dockerCwd = $this->convertWindowsPath($cwd);
} else {
$dockerCwd = $cwd;
}
$cmd = 'docker run -i --rm -v"' . $dockerCwd . '":/src/php-src aboks/php-src-devtools:latest ' . $subcommand;
if (count($arguments) > 0) {
$cmd .= ' ' . implode(' ', $arguments);
}
return new Process($cmd);
}
private function convertWindowsPath(string $path): string
{
$path = strtr($path, '\\', '/');
$path = preg_replace_callback('#^([A-Z]):#', function ($matches) {
return '/' . strtolower($matches[1]);
}, $path);
return $path;
}
}