Skip to content

Commit bbd794c

Browse files
committed
fix: filter argc, argv, ARGC, ARGV
1 parent 4d61832 commit bbd794c

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
"require-dev": {
2424
"mockery/mockery": "^0.9|^1.3",
25-
"orchestra/testbench": "^6.18|^5.19",
26-
"phpunit/phpunit": "^9.1|^8.5"
25+
"orchestra/testbench": "^5.19|^6.18",
26+
"phpunit/phpunit": "^8.5|^9.1"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/ParallelArtisan.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class ParallelArtisan
3131
*/
3232
private $process;
3333

34-
public function __construct(Request $request, array $env = [])
34+
public function __construct(Request $request = null, array $env = [])
3535
{
36-
$this->request = $request;
36+
$this->request = $request ?? Request::capture();
3737
$this->setEnv($env);
3838
}
3939

@@ -105,9 +105,14 @@ private function parseParameters(array $parameters): array
105105

106106
private function getEnv(): array
107107
{
108-
return array_filter(array_merge($this->request->server->all(), $_ENV, $this->env), static function ($env) {
109-
return ! is_array($env);
110-
});
108+
$env = array_merge($this->request->server->all(), $_ENV, $this->env);
109+
foreach (['argc', 'argv', 'ARGC', 'ARGV'] as $key) {
110+
if (array_key_exists($key, $env)) {
111+
unset($env[$key]);
112+
}
113+
}
114+
115+
return $env;
111116
}
112117

113118
private function getPhpBinary(): string

src/ParallelRequest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ class ParallelRequest
1515
use MakesHttpRequests;
1616
use InteractsWithAuthentication;
1717

18+
/**
19+
* @var Request|null
20+
*/
21+
private $request;
22+
1823
/**
1924
* AsyncRequest constructor.
20-
* @param array $serverVariables
25+
* @param Request|null $request
2126
*/
22-
public function __construct(array $serverVariables = [])
27+
public function __construct(Request $request = null)
2328
{
24-
$this->withServerVariables($serverVariables);
29+
$this->request = $request ?? Request::capture();
2530
}
2631

2732
/**
@@ -38,10 +43,10 @@ public function __construct(array $serverVariables = [])
3843
*/
3944
public function call(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null): PromiseInterface
4045
{
41-
$artisan = new ParallelArtisan(Request::capture(), $this->serverVariables);
46+
$artisan = new ParallelArtisan($this->request, $this->serverVariables);
4247
$params = $this->toParams($uri, $method, $parameters, $cookies, $files, $server, $content);
4348

44-
return ($artisan)->call(ParallelCommand::COMMAND_NAME, $params)
49+
return $artisan->call(ParallelCommand::COMMAND_NAME, $params)
4550
->then(function () use ($artisan) {
4651
return $this->updateCookies($this->toResponse($artisan->output()));
4752
});
@@ -66,11 +71,12 @@ public static function setBinary(string $binary): void
6671

6772
/**
6873
* @param array $serverVariables
74+
* @param Request|null $request
6975
* @return $this
7076
*/
71-
public static function create(array $serverVariables = []): self
77+
public static function create(Request $request = null): self
7278
{
73-
return new static($serverVariables);
79+
return new static($request);
7480
}
7581

7682
/**

src/ParallelServiceProvider.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44

55
use Illuminate\Support\ServiceProvider;
66
use Recca0120\LaravelParallel\Console\ParallelCommand;
7-
use Recca0120\LaravelParallel\Tests\ParallelRequest;
87

98
class ParallelServiceProvider extends ServiceProvider
109
{
1110
public function register()
1211
{
1312
$this->commands([ParallelCommand::class]);
14-
15-
$this->app->bind(ParallelRequest::class, function () {
16-
return ParallelRequest::create($this->app['request']->server->all());
17-
});
18-
$this->app->bind(ParallelRequest::class, function () {
19-
return ParallelRequest::create($this->app['request']->server->all());
20-
});
2113
}
2214
}

tests/ParallelRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function test_it_should_return_previous_url(): void
3535

3636
public function test_it_should_has_db_connection_in_server_variables(): void
3737
{
38-
$request = ParallelRequest::create(['CUSTOM' => 'custom']);
38+
$request = ParallelRequest::create()->withServerVariables(['CUSTOM' => 'custom']);
3939

4040
$response = $request->getJson('/server_variables')->wait();
4141

0 commit comments

Comments
 (0)