Comments (11)
The problem here is the issued warning, when stream_resolve_include_path() should not result in a warning, but silently return false instead.
from vfsstream.
After further investigation I believe it's not a bug with vfsStream, but with PHP calling vfsStream's url_stat() method with a wrong value for $flags, therefore vfsStream does not know it must not issue a warning.
However, I'm a bit unsure that I got the bit operations right.
from vfsstream.
Added a test case. It seems stream_resolve_include_path() might not call url_stat() correctly. Needs to be clarified with PHP core.
from vfsstream.
I have the same problem where stream_resolve_include_path()
returns false for vfs://
urls, even though it works fine to fopen()
them. Did you file a bug report with PHP core?
from vfsstream.
No, I didn't, as nobody had an issue with that again. Also, the bug report would have been about the missing flag in the call to the vfsStream method. In your case I suspect there must be something else, as stream_resolve_include_path()
should work just fine when the file exists, see f780403#diff-727ee525c70e3fbdc1c65e385ed866d3R56
from vfsstream.
I'm not sure if it's an edge case, but zendframework/zend-validator uses stream_resolve_include_path
to check if a file exists, see zendframework/zend-validator#77. stream_resolve_include_path
will return something !== false
when the file exists, but that doesn't seem to work with vfsStream
.
To reproduce:
$vfs = org\bovigo\vfs\vfsStream::setup('root', null, ['file' => 'content']);
$file = $vfs->getChild('file');
// echoes bool(false) but should be the path to the file.
var_dump(stream_resolve_include_path($file->url()));
Compare that to:
touch(getcwd() . "/test.tmp");
// echoes /path/to/test.tmp
var_dump(stream_resolve_include_path(getcwd() . "/test.tmp"));
from vfsstream.
In your example you don't add the vfsStream path vfs://root to PHP's include_path, whereas the current working directory usually is added to it automatically by PHP. If you add the vfsStream path to the include path as can be seen in the test I linked to it should be resolved correctly.
from vfsstream.
Any absolute path to an existing file is resolved by stream_resolve_include_path
, not just those in the include path. The problem is that it cannot resolve "absolute" vfs://
urls.
For example, the zend validator relies on the fact that any absolute path to an existing file will return something !== false
. However, when given a vfs://
"absolute url" stream_resolve_include_path
returns false
.
from vfsstream.
Ah, didn't know about that. Just tested, vfsStream doesn't even get called when an absolute vfsStream path is used with stream_resolve_include_path
. So there's nothing that it can do about it - but if it would be called it should work out of the box as vfsStream's url_stat
method would return the correct information.
from vfsstream.
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use org\bovigo\vfs\vfsStream;
$vfs = vfsStream::setup('root');
vfsStream::create(['Hi.php' => '<?php // stuff.'], $vfs);
// checkAndLoad() calls stream_resolve_include_path(). Explosion happens here:
\PHPUnit_Util_Fileloader::checkAndLoad(vfsStream::url('root/Hi.php'));
// [24-Jun-2016 05:38:20 Europe/Berlin] PHP Fatal error: Uncaught PHPUnit_Framework_Exception:
// Cannot open file "vfs://root/Hi.php".
Here's another example. I'm trying to write a PHPUnit test suite loader, and also test the loader. The whole thing is stream safe and can thus be mocked with vfsStream, except for stream_resolve_include_path()
.
This is where I'm working if you're curious: https://www.drupal.org/node/2499239
from vfsstream.
As noted above, there is nothing that vfsStream can do about. I added a remark on this in the list of known issues. If someone wants to make it work please submit a feature/pull request to PHP core - personally I don't have any deeper interest in that, so I won't take care of that.
from vfsstream.
Related Issues (20)
- Directory should not be allowed to move to itself
- `vfsStreamDirectory::getChild()` has absurd complexity HOT 2
- php 8.1: vfsStreamDirectory::getIterator() incompatible with IteratorAggreate
- php 8.1: vfsStreamContainerIterator incompatible with Iterator
- PHP 8.1 Support HOT 4
- Add a setCurrentUser()
- sebastian/resource-operations is abandoned
- Create CSV file in the custom path using VFS HOT 3
- ../ is not correctly recognized in VfsStream HOT 2
- PHP 8.2 Support - track issues here HOT 7
- Allow for custom directory separators HOT 2
- vfsStream::newDirectory() does not return result when called recursively [not a bug, closed] HOT 1
- touch() ignores permissions of existing objects HOT 1
- Best practices: using vfsStream methods vs native filesystem methods HOT 2
- mkdir(recursive: true) behaves wrong for existing directories
- General notes on usage
- Blocker: broken package in github HOT 1
- "vfsStream team" link in Wiki is broken
- file_put_contents fails when vfsStream::setup() was invoked twice. HOT 2
- PHP 8.4 Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vfsstream.