Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
-----------------

Expand All @@ -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
------------
Expand Down Expand Up @@ -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) {
// ...
});
Expand Down
21 changes: 18 additions & 3 deletions src/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/ChildProcess/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public function getLoop()
return $this->loop;
}

/**
* {@inheritDoc}
*/
public function getFilesystem()
{
return $this->filesystem;
}

/**
* {@inheritDoc}
*/
Expand All @@ -145,6 +153,14 @@ public function setFilesystem(FilesystemInterface $filesystem)
];
}

/**
* {@inheritDoc}
*/
public function getInvoker()
{
return $this->invoker;
}

/**
* @param CallInvokerInterface $invoker
* @return void
Expand Down
16 changes: 16 additions & 0 deletions src/Eio/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public function getLoop()
return $this->loop;
}

/**
* {@inheritDoc}
*/
public function getInvoker()
{
return $this->invoker;
}

/**
* {@inheritDoc}
*/
Expand All @@ -126,6 +134,14 @@ public function setInvoker(CallInvokerInterface $invoker)
$this->invoker = $invoker;
}

/**
* {@inheritDoc}
*/
public function getFilesystem()
{
return $this->filesystem;
}

/**
* {@inheritDoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions src/FilesystemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/DuplexStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/GenericStreamInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface GenericStreamInterface
{
/**
* @return resource
* @return mixed
*/
public function getFiledescriptor();
}
2 changes: 1 addition & 1 deletion src/Stream/GenericStreamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/ReadableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/StreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Stream/WritableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions tests/ChildProcess/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
32 changes: 32 additions & 0 deletions tests/Eio/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ protected function mockAdapter(LoopInterface $loop = null)
$mock = $this->getMock('React\Filesystem\AdapterInterface', [
'__construct',
'getLoop',
'getFilesystem',
'setFilesystem',
'getInvoker',
'setInvoker',
'callFilesystem',
'isSupported',
Expand Down