8 ms·
Show HN: Virtual File System in PHP
- noonespecial 12y agoI don't much care for PHP, always using perl in the old days when given the choice, but I sure do wish the PHP I've had to work with over the years looked like this. I don't even care how it works yet, just looking at how well its laid out makes me feel like I can figure it out without much trouble. The comments and variable names alone start to draw me into the "story" as soon as I pop open a file. We don't say it enough to each other. Well done.
- adlawson 12y agoThanks very much :)
- thornag 12y agoI made one some time ago too https://github.com/thornag/php-vfs https://github.com/thornag/php-vfs Similarly, I've been trying to make it behave just like the native functions under unix environment. Think the basic assumptions are the same.
- mkoryak 12y agoWhat is that gif from?
- adlawson 12y agohttps://github.com/adlawson/vfs.php/issues/7 https://github.com/adlawson/vfs.php/issues/7
- adlawson 12y agoI know PHP isn't the "coolest" of languages around, but I thought I'd just show my project I started a few years ago and never really got around to finishing. It's been used before as part of a mustache template runtime evaluator and in test suites. Current issues: - Test coverage is okay but could definitely be improved (currently ~60%) - Symlinks - Proper support for perms/ACL If anyone's got any feedback or wants to contribute, go ahead.
- aceperry 12y agoVery cool project. This pushes the bounds of what I expect, especially from php.
- encoderer 12y agoOne nice upside to the (often negative) impression of PHP is that when you put in some time and produce something kinda cool, you get a lot of positive attention from the community. I experienced this myself on a project to create a multi-processing library for php (https://github.com/shaneharter/PHP-Daemon https://github.com/shaneharter/PHP-Daemon)
- Gigablah 12y agoHm, I wonder if I can marry this with Flysystem (https://github.com/thephpleague/flysystem https://github.com/thephpleague/flysystem) so I can use PHP builtin functions rather than being tied to their API. Maybe I'll give it shot!
- PeterGriffin 12y agoI didn't have time to review the project in detail, but one thing that made an impression on me is having a registry in there. Many projects make the same mistake. The registry/service locator/DI container or whatever flavor you prefer should be an application concern. Applications should create this for themselves, and not every library having its own registry just for instances of its own classes. Similarly you have factories and builders which wrap a constructor and don't add or change anything. You can remove some of that code and focus on the essence of your library. This way it might gain more supporters and contributors.
- benatkin 12y agoThat animated GIF is awesome.
- utmishra 12y agoI am tempted to see similar GIFs in other repos, but then it would be so mainstream.
- canadev 12y agoI am curious, what is the point of using something like this?
- olso 12y agohttps://github.com/adlawson/vfs.php#example-use-cases https://github.com/adlawson/vfs.php#example-use-cases
- zapt02 12y agoHow exactly do you perform runtime php evaluation using this?
- adlawson 12y agoYou write your php to a file in the vfs, then you `require` it back out. There's an example of it in the documentation[1] but a simple example could be: ``` <?php FileSystem::factory('vfs://'); file_put_contents('vfs://foo.php', '<?php echo "Hello, World!";'); require 'vfs://foo.php'; // Hello, World! ``` [1]: https://github.com/adlawson/vfs.php#documentation https://github.com/adlawson/vfs.php#documentation
- blueflow 12y agoPHP may be an ugly language, but these kind of projects are fascinating even if i doubt that i would ever need such a thing. And +1 for that gif.
- nubs 12y agoHow does this compare to vfsStream[1]? I've used that in the past for mocking in unit tests. Does this offer anything more than vfsStream? [1]: https://github.com/mikey179/vfsStream https://github.com/mikey179/vfsStream
- adlawson 12y agoOn the surface of it, there is no real difference. You can use them both with your usual `fopen` and `file_get_contents` builtins. I believe that the implementation is truer to the behaviour of how these builtin functions behave with a unix FS. Amongst some other subtleties, here's some examples: - vfsStream simply ignores handle modifiers (except for +)[1] - some effort has gone into showing where errors were triggered in userland code[2] - node types are represented as `fstat` would see them[3] rather than using simple types[4] vfsStream works perfectly fine, but if you want to use it more with testing file system operations; the closer you are to a true environment the better. Obviously this project isn't quite there yet, but it should be once a few issues have been ironed out. [1]: https://github.com/mikey179/vfsStream/blob/master/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php#L253-L254 https://github.com/mikey179/vfsStream/blob/master/src/main/p... [2]: https://github.com/adlawson/vfs.php/blob/master/src/Logger/PhpErrorLogger.php#L53 https://github.com/adlawson/vfs.php/blob/master/src/Logger/P... [3]: https://github.com/adlawson/vfs.php/blob/master/src/Node/StatInterface.php#L17-L29 https://github.com/adlawson/vfs.php/blob/master/src/Node/Sta... [4]: https://github.com/mikey179/vfsStream/blob/master/src/main/php/org/bovigo/vfs/vfsStreamContent.php#L21-L27 https://github.com/mikey179/vfsStream/blob/master/src/main/p...
- michaelbuckbee 12y agoI'm curious if this would be performant enough to use in something like Heroku. For example a big challenge to running Wordpress on Heroku is that some plugins write out some files, etc
- adlawson 12y agoI don't see why not. It only loads a few objects into memory so the footprint would be tiny, especially when you compare it to running WP. If you can configure the paths these plugins write to, then you can use VFS. Unless the plugin explicitly uses `file://` or they strip the scheme, but I doubt they would.