-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPhpSettingsCommand.php
More file actions
121 lines (108 loc) · 3.85 KB
/
PhpSettingsCommand.php
File metadata and controls
121 lines (108 loc) · 3.85 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of the Webmozarts Console Parallelization package.
*
* (c) Webmozarts GmbH <office@webmozarts.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Webmozarts\Console\Parallelization\Fixtures\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
use Symfony\Component\Filesystem\Filesystem;
use Webmozarts\Console\Parallelization\ErrorHandler\ErrorHandler;
use Webmozarts\Console\Parallelization\Input\ParallelizationInput;
use Webmozarts\Console\Parallelization\Integration\TestDebugProgressBarFactory;
use Webmozarts\Console\Parallelization\Integration\TestLogger;
use Webmozarts\Console\Parallelization\Logger\Logger;
use Webmozarts\Console\Parallelization\Logger\NullLogger;
use Webmozarts\Console\Parallelization\Logger\StandardLogger;
use Webmozarts\Console\Parallelization\ParallelCommand;
use Webmozarts\Console\Parallelization\ParallelExecutorFactory;
use Webmozarts\Console\Parallelization\Parallelization;
use Webmozarts\Console\Parallelization\Process\PhpExecutableFinder;
use function file_get_contents;
use function ini_get;
use function json_decode;
use function realpath;
use function sprintf;
use function xdebug_break;
use const JSON_THROW_ON_ERROR;
final class PhpSettingsCommand extends ParallelCommand
{
public const string MAIN_PROCESS_OUTPUT_DIR = __DIR__.'/../../../dist/php-settings_main-process';
public const string CHILD_PROCESS_OUTPUT_DIR = __DIR__.'/../../../dist/php-settings_child-process';
public function __construct(
private Filesystem $filesystem,
) {
parent::__construct('test:php-settings');
}
/**
* @return list<string>
*/
protected function fetchItems(InputInterface $input, OutputInterface $output): array
{
return ['item0'];
}
protected function getParallelExecutableFactory(
callable $fetchItems,
callable $runSingleCommand,
callable $getItemName,
string $commandName,
InputDefinition $commandDefinition,
ErrorHandler $errorHandler
): ParallelExecutorFactory {
return ParallelExecutorFactory::create(
$fetchItems,
$runSingleCommand,
$getItemName,
$commandName,
$commandDefinition,
$errorHandler,
)
->withRunBeforeFirstCommand(self::runBeforeFirstCommand(...))
->withPhpExecutable([
...PhpExecutableFinder::find(),
'-dmax_input_time=30',
])
->withScriptPath(realpath(__DIR__.'/../../../bin/console'));
}
private function runBeforeFirstCommand(): void
{
$this->dumpMemoryLimit(self::MAIN_PROCESS_OUTPUT_DIR);
}
protected function runSingleCommand(string $item, InputInterface $input, OutputInterface $output): void
{
$this->dumpMemoryLimit(self::CHILD_PROCESS_OUTPUT_DIR);
}
private function dumpMemoryLimit(string $filePath): void
{
$this->filesystem->dumpFile(
$filePath,
sprintf(
'memory_limit=%s%smax_input_time=%s',
ini_get('memory_limit'),
"\n",
ini_get('max_input_time'),
),
);
}
public static function createSettingsOutput(string $memoryLimit, string $maxInputTime): string
{
return sprintf(
'memory_limit=%s%smax_input_time=%s',
$memoryLimit,
"\n",
$maxInputTime,
);
}
protected function getItemName(?int $count): string
{
return 1 === $count ? 'item' : 'items';
}
}