reactphp / filesystem

Evented filesystem access.
MIT License
135 stars 40 forks source link

Version v0.2 doesn't exist in Packagist #100

Closed michaelbutler closed 2 years ago

michaelbutler commented 2 years ago

The README refers to installing ^0.2 but I didn't see that in Packagist and got an error when trying to install it.

But it looks like this was just rewritten 4 days ago! what a coincidence as I'm trying to use it for the first time in a project.

That said, I have a question. Is this a valid alternative to using this project which is still experimental? Sample code follows below:

$path = '/foo/bar/file.css';
if (is_readable($path)) {
    $mimeType = $this->getMimeType($path);
    $fileStream = new ReadableResourceStream(fopen($path, 'rb'));
    $bodyStream = new ReadableBodyStream($fileStream, filesize($path));
    $headers = [
        'Content-Type' => $mimeType,
    ];
    return new \React\Http\Message\Response(200, $headers, $bodyStream);
}

I know already this example violates some of the async principles, for example these are all blocking: is_readable, fopen, filesize but this is only for a dev-convenience function not for production use. I have confirmed this works thus far, but wanted to see if this reactphp/filesystem project could be used as a more proper implementation. Thanks!

WyriHaximus commented 2 years ago

The README refers to installing ^0.2 but I didn't see that in Packagist and got an error when trying to install it.

Correct, the initial, big chunk, of work of the rewrite is done. v0.2.0 isn't out yet as a bunch of smaller improvements/bug fixes will need to be addressed. We didn't wait to wait to get the 80% of the features/changes available before working on the other 20% (which will probably take the other 80% of the time 😂 ).

But it looks like this was just rewritten 4 days ago! what a coincidence as I'm trying to use it for the first time in a project.

Please try it out and let us know how it worked for what you wanted to use it for. We need feedback like that.

That said, I have a question. Is this a valid alternative to using this project which is still experimental?

Yes, or well, I would. v0.1.x was experimental and I learned a lot from creating that version, including many many mistakes. v0.2 aims to take those lettings and mature this package into a stable version like our other components.

$path = '/foo/bar/file.css';
if (is_readable($path)) {
    $mimeType = $this->getMimeType($path);
    $fileStream = new ReadableResourceStream(fopen($path, 'rb'));
    $bodyStream = new ReadableBodyStream($fileStream, filesize($path));
    $headers = [
        'Content-Type' => $mimeType,
    ];
    return new \React\Http\Message\Response(200, $headers, $bodyStream);
}

I know already this example violates some of the async principles, for example these are all blocking: is_readable, fopen, filesize but this is only for a dev-convenience function not for production use. I have confirmed this works thus far, but wanted to see if this reactphp/filesystem project could be used as a more proper implementation. Thanks!

Try this, it doesn't stream the file's contents, but maybe we can add that in v0.2 (or v0.3 as well):

$path = '/foo/bar/file.css';
$this->getMimeType($path);
$filesystem->exists($path)->then(
    static fn (FileInterface $file): PromiseInterface => $file->getContents()
)->then(
    static fn (string $contents): ResponseInterface => new \React\Http\Message\Response(200, [
        'Content-Type' => $mimeType,
    ], $contents)
)

(I didn't check this code for mistakes or try to run it, bugs might be inside 😜 .)

P.S. I took the liberty of editing your comment and enable PHP syntax highlighting to your code example by appending php to the opening of that code block like so it is easier to read:

```php
michaelbutler commented 2 years ago

Hmm... alright so how would I install the latest development version to test? I tried running: composer require 'react/filesystem:dev-master' and got this composer error:

composer require 'react/filesystem:dev-master'                                                                                  2 ✘ 
./composer.json has been updated
Running composer update react/filesystem
Loading composer repositories with package information
Updating dependencies                                 
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - wyrihaximus/react-child-process-promise-closure 1.0.0 requires php ^7.0 -> your php version (8.1.2) does not satisfy that requirement.
    - react/filesystem dev-master requires wyrihaximus/react-child-process-promise-closure ^1.0 -> satisfiable by wyrihaximus/react-child-process-promise-closure[1.0.0].
    - Root composer.json requires react/filesystem dev-master -> satisfiable by react/filesystem[dev-master].

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

So looks like wyrihaximus/react-child-process-promise-closure has to be updated too?

WyriHaximus commented 2 years ago

So looks like wyrihaximus/react-child-process-promise-closure has to be updated too?

Yes, working on that right now 👍 .

WyriHaximus commented 2 years ago

@michaelbutler It should be requireable now