-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from phpsu/feature/add-conditional-arguments
BC: add conditionals for builder and command
- Loading branch information
Showing
6 changed files
with
131 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Chris Ben", | ||
"name": "Christian Rodriguez Benthake", | ||
"email": "[email protected]" | ||
} | ||
], | ||
|
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPSu\ShellCommandBuilder; | ||
|
||
trait ShellConditional | ||
{ | ||
public function if(bool $condition, callable $callback, callable $alternativeCallback = null): self | ||
{ | ||
if ($condition) { | ||
$result = $callback($this); | ||
assert($result instanceof self); | ||
return $result; | ||
} | ||
if ($alternativeCallback) { | ||
$alternativeResult = $alternativeCallback($this); | ||
assert($alternativeResult instanceof self); | ||
return $alternativeResult; | ||
} | ||
return $this; | ||
} | ||
|
||
public function ifThis(callable $callOnThis, callable $callback, callable $alternativeCallback = null): self | ||
{ | ||
return $this->if($callOnThis($this) === true, $callback, $alternativeCallback); | ||
} | ||
} |
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