From 14065ebb7632f98c8875bbd9ad7a3789426f4f49 Mon Sep 17 00:00:00 2001 From: Charlotte Dunois Date: Fri, 25 Jan 2019 10:25:35 +0100 Subject: [PATCH] Add getters for setters and add fs class method to interface --- README.md | 8 +++---- src/AdapterInterface.php | 21 +++++++++++++++--- src/ChildProcess/Adapter.php | 16 ++++++++++++++ src/Eio/Adapter.php | 16 ++++++++++++++ src/FilesystemInterface.php | 6 +++++ src/Stream/DuplexStream.php | 2 +- src/Stream/GenericStreamInterface.php | 2 +- src/Stream/GenericStreamTrait.php | 2 +- src/Stream/ReadableStream.php | 2 +- src/Stream/StreamFactory.php | 2 +- src/Stream/WritableStream.php | 2 +- tests/ChildProcess/AdapterTest.php | 32 +++++++++++++++++++++++++++ tests/Eio/AdapterTest.php | 32 +++++++++++++++++++++++++++ tests/TestCase.php | 2 ++ 14 files changed, 132 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ee0ec2b3..239e0ba7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Filesystem ========== -Evented filesystem access utilizing [EIO](http://php.net/eio). - [![Build Status](https://secure.travis-ci.org/reactphp/filesystem.png?branch=master)](http://travis-ci.org/reactphp/filesystem) [![Code Climate](https://codeclimate.com/github/reactphp/filesystem/badges/gpa.svg)](https://codeclimate.com/github/reactphp/filesystem) +[ReactPHP](https://reactphp.org/)'s evented asynchronous, non-blocking filesystem access library. + Table of Contents ----------------- @@ -23,7 +23,7 @@ Table of Contents Introduction ------------ -Filesystem WIP for [EIO](http://php.net/eio), keep in mind that this can be very unstable at times and is not stable by a long shot! +`react/filesystem` is a package to power your application with asynchronous, non-blocking filesystem access. Asynchronous access is enabled by various adapters described below. Adapters ------------ @@ -70,7 +70,7 @@ Which is a convenience method for: ```php $filesystem->file('test.txt')->open('r')->then(function($stream) { - return React\Stream\BufferedSink::createPromise($stream); + return \React\Stream\BufferedSink::createPromise($stream); })->then(function($contents) { // ... }); diff --git a/src/AdapterInterface.php b/src/AdapterInterface.php index 9d94496d..34dadb40 100644 --- a/src/AdapterInterface.php +++ b/src/AdapterInterface.php @@ -24,6 +24,21 @@ public static function isSupported(); */ public function getLoop(); + /** + * Get the relevant filesystem for this adapter. + * + * @internal + * @return FilesystemInterface + */ + public function getFilesystem(); + + /** + * Get the call invoker for this adapter. + * + * @return CallInvokerInterface + */ + public function getInvoker(); + /** * Set the relevant filesystem for this adapter. * @@ -143,7 +158,7 @@ public function open($path, $flags, $mode = self::CREATION_MODE); /** * Read from the given file descriptor. * - * @param $fileDescriptor + * @param mixed $fileDescriptor * @param int $length * @param int $offset * @return PromiseInterface @@ -153,7 +168,7 @@ public function read($fileDescriptor, $length, $offset); /** * Write to the given file descriptor. * - * @param $fileDescriptor + * @param mixed $fileDescriptor * @param string $data * @param int $length * @param int $offset @@ -164,7 +179,7 @@ public function write($fileDescriptor, $data, $length, $offset); /** * Close the given file descriptor. * - * @param resource $fd + * @param mixed $fd * @return PromiseInterface */ public function close($fd); diff --git a/src/ChildProcess/Adapter.php b/src/ChildProcess/Adapter.php index be0ee398..cea8cffd 100644 --- a/src/ChildProcess/Adapter.php +++ b/src/ChildProcess/Adapter.php @@ -132,6 +132,14 @@ public function getLoop() return $this->loop; } + /** + * {@inheritDoc} + */ + public function getFilesystem() + { + return $this->filesystem; + } + /** * {@inheritDoc} */ @@ -145,6 +153,14 @@ public function setFilesystem(FilesystemInterface $filesystem) ]; } + /** + * {@inheritDoc} + */ + public function getInvoker() + { + return $this->invoker; + } + /** * @param CallInvokerInterface $invoker * @return void diff --git a/src/Eio/Adapter.php b/src/Eio/Adapter.php index 361224ec..9fa82fc9 100644 --- a/src/Eio/Adapter.php +++ b/src/Eio/Adapter.php @@ -118,6 +118,14 @@ public function getLoop() return $this->loop; } + /** + * {@inheritDoc} + */ + public function getInvoker() + { + return $this->invoker; + } + /** * {@inheritDoc} */ @@ -126,6 +134,14 @@ public function setInvoker(CallInvokerInterface $invoker) $this->invoker = $invoker; } + /** + * {@inheritDoc} + */ + public function getFilesystem() + { + return $this->filesystem; + } + /** * {@inheritDoc} */ diff --git a/src/FilesystemInterface.php b/src/FilesystemInterface.php index a2c4d1be..9cd3898d 100644 --- a/src/FilesystemInterface.php +++ b/src/FilesystemInterface.php @@ -51,6 +51,12 @@ public function dir($path); */ public function link($path, Node\NodeInterface $destination); + /** + * @param string $path + * @return \React\Promise\PromiseInterface + */ + public function constructLink($path); + /** * @param string $filename * @return \React\Promise\PromiseInterface diff --git a/src/Stream/DuplexStream.php b/src/Stream/DuplexStream.php index f00e5f9e..37aec595 100644 --- a/src/Stream/DuplexStream.php +++ b/src/Stream/DuplexStream.php @@ -14,7 +14,7 @@ class DuplexStream extends EventEmitter implements DuplexStreamInterface, Generi /** * @param string $path - * @param resource $fileDescriptor + * @param mixed $fileDescriptor * @param AdapterInterface $filesystem */ public function __construct($path, $fileDescriptor, AdapterInterface $filesystem) diff --git a/src/Stream/GenericStreamInterface.php b/src/Stream/GenericStreamInterface.php index 931529ad..061fdbd8 100644 --- a/src/Stream/GenericStreamInterface.php +++ b/src/Stream/GenericStreamInterface.php @@ -5,7 +5,7 @@ interface GenericStreamInterface { /** - * @return resource + * @return mixed */ public function getFiledescriptor(); } diff --git a/src/Stream/GenericStreamTrait.php b/src/Stream/GenericStreamTrait.php index afe24034..e7515401 100644 --- a/src/Stream/GenericStreamTrait.php +++ b/src/Stream/GenericStreamTrait.php @@ -13,7 +13,7 @@ trait GenericStreamTrait /** * @param string $path - * @param resource $fileDescriptor + * @param mixed $fileDescriptor * @param AdapterInterface $filesystem */ public function __construct($path, $fileDescriptor, AdapterInterface $filesystem) diff --git a/src/Stream/ReadableStream.php b/src/Stream/ReadableStream.php index 8630c201..cdb59867 100644 --- a/src/Stream/ReadableStream.php +++ b/src/Stream/ReadableStream.php @@ -13,7 +13,7 @@ class ReadableStream extends EventEmitter implements GenericStreamInterface, Rea /** * @param string $path - * @param resource $fileDescriptor + * @param mixed $fileDescriptor * @param AdapterInterface $filesystem */ public function __construct($path, $fileDescriptor, AdapterInterface $filesystem) diff --git a/src/Stream/StreamFactory.php b/src/Stream/StreamFactory.php index baa358ab..e2fe2e17 100644 --- a/src/Stream/StreamFactory.php +++ b/src/Stream/StreamFactory.php @@ -8,7 +8,7 @@ class StreamFactory { /** * @param string $path - * @param resource $fileDescriptor + * @param mixed $fileDescriptor * @param int $flags * @param AdapterInterface $filesystem * @return DuplexStream|ReadableStream|WritableStream diff --git a/src/Stream/WritableStream.php b/src/Stream/WritableStream.php index 450fb497..d1cfb787 100644 --- a/src/Stream/WritableStream.php +++ b/src/Stream/WritableStream.php @@ -13,7 +13,7 @@ class WritableStream extends EventEmitter implements GenericStreamInterface, Wri /** * @param string $path - * @param resource $fileDescriptor + * @param mixed $fileDescriptor * @param AdapterInterface $filesystem */ public function __construct($path, $fileDescriptor, AdapterInterface $filesystem) diff --git a/tests/ChildProcess/AdapterTest.php b/tests/ChildProcess/AdapterTest.php index 9fa07a51..fd7631aa 100644 --- a/tests/ChildProcess/AdapterTest.php +++ b/tests/ChildProcess/AdapterTest.php @@ -36,6 +36,38 @@ public function testGetLoop() $this->assertSame($loop, $filesystem->getLoop()); } + public function testGetSetFilesystem() + { + $loop = $this->getMock('React\EventLoop\LoopInterface'); + $filesystem = new Adapter($loop, [ + 'pool' => [ + 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', + ], + ]); + + $this->assertNull($filesystem->getFilesystem()); + $fs = \React\Filesystem\Filesystem::createFromAdapter($this->mockAdapter()); + $filesystem->setFilesystem($fs); + + $this->assertSame($fs, $filesystem->getFilesystem()); + } + + public function testGetSetInvoker() + { + $loop = $this->getMock('React\EventLoop\LoopInterface'); + $filesystem = new Adapter($loop, [ + 'pool' => [ + 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', + ], + ]); + + $invoker = new \React\Filesystem\InstantInvoker($filesystem); + $this->assertNotSame($invoker, $filesystem->getInvoker()); + + $filesystem->setInvoker($invoker); + $this->assertSame($invoker, $filesystem->getInvoker()); + } + public function callFilesystemProvider() { return [ diff --git a/tests/Eio/AdapterTest.php b/tests/Eio/AdapterTest.php index 9105c4a8..998c80ff 100644 --- a/tests/Eio/AdapterTest.php +++ b/tests/Eio/AdapterTest.php @@ -35,6 +35,38 @@ public function testGetLoop() $this->assertSame($loop, $filesystem->getLoop()); } + public function testGetSetFilesystem() + { + $loop = $this->getMock('React\EventLoop\LoopInterface'); + $filesystem = new Adapter($loop, [ + 'pool' => [ + 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', + ], + ]); + + $this->assertNull($filesystem->getFilesystem()); + $fs = \React\Filesystem\Filesystem::createFromAdapter($this->mockAdapter()); + $filesystem->setFilesystem($fs); + + $this->assertSame($fs, $filesystem->getFilesystem()); + } + + public function testGetSetInvoker() + { + $loop = $this->getMock('React\EventLoop\LoopInterface'); + $filesystem = new Adapter($loop, [ + 'pool' => [ + 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', + ], + ]); + + $invoker = new \React\Filesystem\InstantInvoker($filesystem); + $this->assertNotSame($invoker, $filesystem->getInvoker()); + + $filesystem->setInvoker($invoker); + $this->assertSame($invoker, $filesystem->getInvoker()); + } + public function testCallFilesystemCallsProvider() { $pathName = 'foo.bar'; diff --git a/tests/TestCase.php b/tests/TestCase.php index 5bfb711c..6d5fb585 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,7 +24,9 @@ protected function mockAdapter(LoopInterface $loop = null) $mock = $this->getMock('React\Filesystem\AdapterInterface', [ '__construct', 'getLoop', + 'getFilesystem', 'setFilesystem', + 'getInvoker', 'setInvoker', 'callFilesystem', 'isSupported',