Skip to content

Commit

Permalink
Reduced required PHP version to 7.1 for possible future proc_open r…
Browse files Browse the repository at this point in the history
…emoval, add shortcut functions

This package is no longer `proc_open` focused as such **symfony/process** changes will not be tracked. Any bug fixes for the fallback methods based on `proc_open`  will be addressed within this package.
- add function to handle base64 being returned by child process
- add function to return Channeled objects
  • Loading branch information
TheTechsTech committed Apr 26, 2020
1 parent 429f195 commit 02ed3ed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ $process->displayOn()->run();
```php
include 'vendor/autoload.php';

use Async\Spawn\Channeled;
use Async\Spawn\ChanneledInterface;

$ipc = new Channeled();
// return a new `Channeled` instance.
$ipc = \spawn_channel();;

$process = spawn(function (ChanneledInterface $channel) {
// Setup the channel resources if needed, defaults to `STDIN`, `STDOUT`, and `STDERR`.
Expand Down
26 changes: 26 additions & 0 deletions Spawn/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Async\Spawn\Channeled;
use Async\Spawn\ChanneledInterface;
use Async\Spawn\Spawn;
use Async\Spawn\LauncherInterface;

Expand Down Expand Up @@ -233,6 +234,16 @@ function spawn_result(LauncherInterface $process)
return $process->getResult();
}

/**
* return a new **Spawn** based `Channel` instance.
*
* @return ChanneledInterface
*/
function spawn_channel(): ChanneledInterface
{
return new Channeled;
}

/**
* Check if a string is base64 valid, or has `encoded` mixed data.
*
Expand Down Expand Up @@ -266,6 +277,21 @@ function is_base64($input): ?bool
return false;
}

/**
* Check if base64 valid, if so decodes and creates a `PHP` value from the
* **serialized** decoded data representation.
*
* @param string $input
*
* @return mixed
*
* @codeCoverageIgnore
*/
function deserialize($input)
{
return \is_base64($input) ? \unserialize(\base64_decode($input)) : $input;
}

/**
* For use when/before calling the actual `return` keyword, will write some `INVALID` data to standard
* output and flush, then sleep for `microsecond`, and return the to be encoded `data/result`.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
}
],
"require": {
"php": ">7.2",
"php": ">7.1",
"opis/closure": "^3.5.1",
"symfony/process": "^5.0.7"
"symfony/process": ">4.0.0"
},
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion tests/ChanneledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function setUp(): void

public function testSimpleChanneled()
{
$ipc = new Channeled();
$ipc = \spawn_channel();

$process = \spawn(function (ChanneledInterface $channel) {
$channel->write('ping');
Expand Down

0 comments on commit 02ed3ed

Please sign in to comment.