Matthimatiker / MolComponents

Library with use-at-will architecture that extends the functionality of Zend Framework 1. Main features: Improved bootstrapping with lazy loading of resources, declaration of request parameters as argument in controller actions, advanced form creation and validation, mail templates, lightweight controller testing.
Other
2 stars 0 forks source link

Mol_Util_MemoryStream: stream_metadata is not implemented! #71

Closed bonndan closed 11 years ago

bonndan commented 11 years ago

calling touch() on the stream leads to the error:

stream_metadata is not implemented!

Matthimatiker commented 11 years ago

The method stream_metadata() was added with PHP 5.4, which seems to be the reason why it is not implemented yet. Regardless of that, the memory stream is not meant for filesystem replacement and I have currently no idea how to implement this without creating a great feature gap (and possible system inconsistencies) between PHP 5.3 and 5.4.

You could have a look at projects like Gaufrette (https://github.com/KnpLabs/Gaufrette) or vfsStream (https://packagist.org/packages/mikey179/vfsStream), which offer more sophisticated features and aim to provide full filesystem abstraction.

Nevertheless, if you have a good idea how to overcome the problem with different PHP versions and would like to see this feature in the memory stream, feel free to create a pull request. The basics about stream wrappers are listed in the PHP documentation (http://php.net/manual/en/class.streamwrapper.php), although it is sometimes hard to figure out the details.

I would prefer to delay support for this feature until PHP 5.3 is outdated and PHP 5.4 is broadly adopted.

bonndan commented 11 years ago

Imho a statement that memory stream is not meant for filesystem replacement could be added to the class documentation. The current description "May be used with functions that usually write to files only." might be misleading.

From the PHP docu at http://www.php.net/manual/en/streamwrapper.stream-metadata.php : "Returns TRUE on success or FALSE on failure. If option is not implemented, FALSE should be returned."

Adding a stub method stream_metadata() returning false would not harm PHP 5.3 and make it compatible to PHP 5.4 under the given constraint that it is not meant as full filesystem replacement.

Matthimatiker commented 11 years ago

Imho a statement that memory stream is not meant for filesystem replacement could be added to the class documentation. The current description "May be used with functions that usually write to files only." might be misleading.

Within the next days I will add a note that it does not work with functions like touch().

Adding a stub method stream_metadata() returning false would not harm PHP 5.3 and make it compatible to PHP 5.4 under the given constraint that it is not meant as full filesystem replacement.

That is exactly what I meant by version inconsistencies. Adding PHP 5.4 specific code might hide this problem in that version. Nevertheless, the issue still exists with PHP 5.3 and it does not seem to be fixable there.

Think of developers that use 5.4 for development, but have to deploy to 5.3 systems sometimes. In this case the problem sneaks into production and might cause further problems.

Currently, the code (unintentionally) follows the fail-fast-principle and it is consistent: It breaks immediately with all versions. Consistently.

Matthimatiker commented 11 years ago

I used Travis to test this, and by implementing stream_metadata() PHP 5.4 completely ignores the problem.