Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~~is_dir() not implemented~~ in "0.4.0" #15

Closed
BrianHenryIE opened this issue Jan 29, 2025 · 3 comments · Fixed by #16
Closed

~~is_dir() not implemented~~ in "0.4.0" #15

BrianHenryIE opened this issue Jan 29, 2025 · 3 comments · Fixed by #16

Comments

@BrianHenryIE
Copy link

BrianHenryIE commented Jan 29, 2025

Great project, thank you.

False alarm: I have 0.4.0 installed.

I'm working on a WordPress related project so still working with PHP 7.4.

https://www.php.net/manual/en/function.stream-wrapper-register.php#51855

If you plan to use your wrapper in a require_once you need to define stream_stat(). If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().

I guess that's not implemented.

Seems is_dir() goes to StreamWrapper::url_stat() which calls FilesystemReader::fileExists() which is not correct for directories.

$testDirAbsolutePath = '/my/test/dir/';

$pathNormalizer = \Elazar\Flystream\ServiceLocator::get(\League\Flysystem\PathNormalizer::class);
$adapter = new \League\Flysystem\Local\LocalFilesystemAdapter('/');
$filesystem = new \League\Flysystem\Filesystem($adapter, [], $pathNormalizer);

$registry = \Elazar\Flystream\ServiceLocator::get(\Elazar\Flystream\FilesystemRegistry::class);
$registry->register('mem', $filesystem);

$makeDirTarget = sprintf(
    "mem://%s%s/",
    ltrim($testDirAbsolutePath, '/\\'),
    'foo'
);

mkdir($makeDirTarget);

// I can see the directory on the filesystem via `ls` in terminal.

$result = is_dir($makeDirTarget);
// false.

$makeFileTarget = $makeDirTarget . 'bar.txt';

file_put_contents($makeFileTarget, 'Hello, world!');

// I can `cat` the file in Terminal.

$result2 = is_dir($makeDirTarget);
//false

$result3 = file_get_contents($makeFileTarget);
// Hello, world!

I'll keep reading and make a PR if I don't get distracted.

@BrianHenryIE BrianHenryIE changed the title is_dir() not implemented ~~is_dir() not implemented~~ in "0.4.0" Jan 29, 2025
@BrianHenryIE
Copy link
Author

I'm digging to get this working with PHP 7.4. It's not an issue for modern developers.

@elazar
Copy link
Owner

elazar commented Jan 29, 2025

Great project, thank you.

@BrianHenryIE Thank you for filing this issue and for using this project!

Official support for PHP 7.4 ended over two years ago; I'd highly recommend upgrading as soon as it's feasible for you to do so.

That said, if you're willing to go to the trouble of getting this project working for that version, I'm guessing you have circumstances restricting you to 7.4 for the time being.

Unfortunately, this project has very much been both a labor of love and a learning experience for me, so earlier versions had a fair amount of bugs and missing behavior. 😅

I'd imagine this block is probably the one you would need to look at backporting.

If you'd like to submit a PR with your fix branched from the 0.4.0 tag, I'd be fine with cutting a 0.5.0 release for others who might be in your situation.

@BrianHenryIE
Copy link
Author

As they say, it's nice to be important but it's more important to be https://xkcd.com/2347/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants