PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File System » File_Find » Bug #7966

File_Find Stream Support

Details

Request #7966File_Find Stream Support
Submitted2006-06-23 00:43 UTC
Fromahayes at wcg dot net dot au
Assigneddoconnor
StatusClosed
PackageFile_Find
PHP Version5.1.4
OSFC5
Roadmaps(Not assigned)

Comments

[2006-06-23 00:43 UTC] ahayes at wcg dot net dot au

Description:
------------
It would be really nice if File_Find had support for streams.

It almost has basic support for streams, if we do not bother about context's, however it would not be hard to integrate context support.

There are a few places that cause stream support to fail, mainly because of searching and replacing of DIRECTORY_SEPARATOR, which while I'm not exactly sure why it has been done I assume it is for security reasons.

For example, lets assume we have a stream as follows:

$files = File_Find::search("ftp://example.com/pub/*.txt");

In its current form, File_Find replaces the directory to read as follows:

ftp:/example.com/pub/*.txt

Notice the missing / in the stream path, causing the stream path to be invalid.

By removing or changing these replacements as listed below basic stream support is enabled. It would not be too hard to also include context support, either in the constructor or within the search and glob functions.

- Line 138 ( $directory = preg_replace("![\\\\/]+!", DIRECTORY_SEPARATOR, $directory); )
- Line 198/199 ( $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); )

Can these lines be replaced by something that does not destroy the stream part?

Test script:
---------------
$files = File_Find::search("file:///tmp");

Expected result:
----------------
Should return some files in the /tmp directory

Actual result:
--------------
PEAR Error is returned as follows:

[pear_error: message="Cannot open directory" code=0 mode=callback callback=Controller::PEAR_Error_Handler prefix="" info=""]

[2006-06-23 07:18 UTC] ahayes at wcg dot net dot au

As in Stream Contexts (http://au2.php.net/manual/en/ref.stream.php).

Resource Contexts would be useful, say for instance as follows:

=========8<============
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);

$context = stream_context_create($opts);

/* Sends an http request to www.example.com
with additional headers shown above */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
=========>8===========

So I imagine that it would not be to hard to pass thru a context resource into File_Find either in the constructor or as an optional param at the end of either File_Find::search and File_Find::glob