Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for getting raw parameters without validation
- Loading branch information
Showing
14 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Castor\Console\Command; | ||
|
||
use Castor\Attribute\AsSymfonyTask; | ||
use Castor\Console\Input\Input; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
@@ -67,10 +68,12 @@ protected function configure(): void | |
} | ||
} | ||
|
||
/** | ||
* @var Input $input | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
Check failure on line 74 in src/Console/Command/SymfonyTaskCommand.php GitHub Actions / Static Analysis
|
||
{ | ||
$r = new \ReflectionProperty($input, 'tokens'); | ||
$extra = array_filter($r->getValue($input), fn ($item) => $item !== $this->taskAttribute->name); | ||
$extra = array_filter($input->getRawParameters(), fn ($item) => $item !== $this->taskAttribute->name); | ||
|
||
$p = new Process([...$this->taskAttribute->console, $this->taskAttribute->originalName, ...$extra]); | ||
$p->run(fn ($type, $bytes) => print ($bytes)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Castor\Console\Input; | ||
|
||
use Symfony\Component\Console\Input\ArgvInput; | ||
|
||
class Input extends ArgvInput | ||
{ | ||
public function getRawParameters() | ||
{ | ||
return (fn () => $this->tokens)->bindTo($this, ArgvInput::class)(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Castor\Tests\Examples\Generated; | ||
|
||
use Castor\Tests\TaskTestCase; | ||
|
||
class ArgPassthruExpanded extends TaskTestCase | ||
{ | ||
// args:passthru | ||
public function test(): void | ||
{ | ||
$process = $this->runTask(['args:passthru', 'a', 'b', '--no', '--foo', 'bar', '-x']); | ||
|
||
$this->assertSame(0, $process->getExitCode()); | ||
$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); | ||
if (file_exists(__FILE__ . '.err.txt')) { | ||
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); | ||
} else { | ||
$this->assertSame('', $process->getErrorOutput()); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Examples/Generated/ArgPassthruExpanded.php.output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
array(8) { | ||
[0]=> | ||
string(9) "--no-ansi" | ||
[1]=> | ||
string(13) "args:passthru" | ||
[2]=> | ||
string(1) "a" | ||
[3]=> | ||
string(1) "b" | ||
[4]=> | ||
string(4) "--no" | ||
[5]=> | ||
string(5) "--foo" | ||
[6]=> | ||
string(3) "bar" | ||
[7]=> | ||
string(2) "-x" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Castor\Tests\Examples\Generated; | ||
|
||
use Castor\Tests\TaskTestCase; | ||
|
||
class ArgsPassthruTest extends TaskTestCase | ||
{ | ||
// args:passthru | ||
public function test(): void | ||
{ | ||
$process = $this->runTask(['args:passthru']); | ||
|
||
$this->assertSame(0, $process->getExitCode()); | ||
$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); | ||
if (file_exists(__FILE__ . '.err.txt')) { | ||
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); | ||
} else { | ||
$this->assertSame('', $process->getErrorOutput()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
array(2) { | ||
[0]=> | ||
string(9) "--no-ansi" | ||
[1]=> | ||
string(13) "args:passthru" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters