Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: specify next release bump minimum version of psalm add Streams entrypoint remove unreachable null coalesce
- Loading branch information
Showing
10 changed files
with
268 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\Stream; | ||
|
||
final class Streams | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
public static function of(): self | ||
{ | ||
return new self; | ||
} | ||
|
||
public function temporary(): Streams\Temporary | ||
{ | ||
return Streams\Temporary::of(); | ||
} | ||
|
||
public function readable(): Streams\Readable | ||
{ | ||
return Streams\Readable::of(); | ||
} | ||
|
||
public function writable(): Streams\Writable | ||
{ | ||
return Streams\Writable::of(); | ||
} | ||
|
||
public function watch(): Streams\Watch | ||
{ | ||
return Streams\Watch::of(); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\Stream\Streams; | ||
|
||
use Innmind\Stream\Readable as Read; | ||
use Innmind\Url\Path; | ||
|
||
final class Readable | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function of(): self | ||
{ | ||
return new self; | ||
} | ||
|
||
public function open(Path $path): Read | ||
{ | ||
return Read\Stream::open($path); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\Stream\Streams; | ||
|
||
use Innmind\Stream\{ | ||
Bidirectional, | ||
Stream, | ||
}; | ||
|
||
final class Temporary | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function of(): self | ||
{ | ||
return new self; | ||
} | ||
|
||
public function new(): Bidirectional | ||
{ | ||
return Stream\Bidirectional::of(\fopen('php://temp', 'r+')); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\Stream\Streams; | ||
|
||
use Innmind\Stream\{ | ||
Watch as WatchInterface, | ||
Watch\Select, | ||
}; | ||
use Innmind\TimeContinuum\ElapsedPeriod; | ||
|
||
final class Watch | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function of(): self | ||
{ | ||
return new self; | ||
} | ||
|
||
public function timeoutAfter(ElapsedPeriod $timeout): WatchInterface | ||
{ | ||
return Select::timeoutAfter($timeout); | ||
} | ||
|
||
public function waitForever(): WatchInterface | ||
{ | ||
return Select::waitForever(); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\Stream\Streams; | ||
|
||
use Innmind\Stream\Writable as Write; | ||
use Innmind\Url\Path; | ||
|
||
final class Writable | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function of(): self | ||
{ | ||
return new self; | ||
} | ||
|
||
public function open(Path $path): Write | ||
{ | ||
return Write\Stream::of(\fopen($path->toString(), 'w')); | ||
} | ||
} |
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,99 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Tests\Innmind\Stream; | ||
|
||
use Innmind\Stream\{ | ||
Streams, | ||
Watch\Select, | ||
}; | ||
use Innmind\TimeContinuum\Earth\ElapsedPeriod; | ||
use Innmind\Url\Path; | ||
use Innmind\Immutable\Str; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StreamsTest extends TestCase | ||
{ | ||
public function testOpeningATemporaryStreamAlwaysReturnANewOne() | ||
{ | ||
$streams = Streams::of(); | ||
$a = $streams->temporary()->new()->write(Str::of('a'))->match( | ||
static fn($a) => $a, | ||
static fn() => null, | ||
); | ||
$b = $streams->temporary()->new()->write(Str::of('b'))->match( | ||
static fn($a) => $a, | ||
static fn() => null, | ||
); | ||
|
||
$this->assertNotNull($a); | ||
$this->assertNotNull($b); | ||
$this->assertNotSame($a, $b); | ||
$this->assertSame( | ||
'a', | ||
$a->toString()->match( | ||
static fn($string) => $string, | ||
static fn() => null, | ||
), | ||
); | ||
$this->assertSame( | ||
'b', | ||
$b->toString()->match( | ||
static fn($string) => $string, | ||
static fn() => null, | ||
), | ||
); | ||
} | ||
|
||
public function testOpenReadable() | ||
{ | ||
$self = Streams::of() | ||
->readable() | ||
->open(Path::of(__FILE__)) | ||
->toString() | ||
->match( | ||
static fn($self) => $self, | ||
static fn() => null, | ||
); | ||
|
||
$this->assertSame(\file_get_contents(__FILE__), $self); | ||
} | ||
|
||
public function testOpenWritable() | ||
{ | ||
$path = Path::of(\tempnam(\sys_get_temp_dir(), 'streams')); | ||
$streams = Streams::of(); | ||
$streams | ||
->writable() | ||
->open($path) | ||
->write(Str::of('foo')); | ||
|
||
$this->assertSame( | ||
'foo', | ||
$streams | ||
->readable() | ||
->open($path) | ||
->toString() | ||
->match( | ||
static fn($string) => $string, | ||
static fn() => null, | ||
), | ||
); | ||
} | ||
|
||
public function testWatch() | ||
{ | ||
$this->assertInstanceOf( | ||
Select::class, | ||
Streams::of() | ||
->watch() | ||
->waitForever(), | ||
); | ||
$this->assertInstanceOf( | ||
Select::class, | ||
Streams::of() | ||
->watch() | ||
->timeoutAfter(new ElapsedPeriod(1)), | ||
); | ||
} | ||
} |