You are here: Re: Streams and wrappers « PHP Programming Language « IT news, forums, messages
Re: Streams and wrappers

Posted by shimmyshack on 06/26/07 03:57

On Jun 25, 4:11 pm, Julien Biezemans <jb@jb> wrote:
> Hi!
>
> Here is another post concerning stream wrappers. I'm trying to implement
> a urn: scheme stream wrapper but this does not seem possible with PHP.
>
> Why? Because PHP analyzes URI with the following syntax:
>
> scheme "://" target
>
> Where _scheme_ is what they incorrectly call a "protocol" in the
> documentation and _target_ the actual target of the URI.
>
> When dealing with things likehttp://www...,ftp://ftp..., everything is ok.
>
> But how are we supposed to support things like mailto:u...@domain.com,
> urn:xmpp:..., h323:host... and other schemes that are NOT followed by
> "://" but only ":"?
>
> If you try to register the mailto "protocol" (which is, again, not the
> correct term), you will do:
>
> stream_wrapper_register('mailto', 'MyMailToClass');
>
> But this wrapper class will not be used at all by PHP if you try this:
>
> fopen('mailto:u...@domain.com', 'w');
>
> Instead you will have to write:
>
> fopen('mailto://u...@domain.com', 'w');
>
> Which is wrong (seehttp://www.rfc-editor.org/rfc/rfc2368.txt).
>
> PHP consider that 'mailto:u...@domain.com' falls into the default
> (file://) scheme as it does not find the "://" string after the
> so-called "protocol".
>
> We may intercept URI's not containing those "://" characters with a
> custom file:// stream wrapper. When the wrapper is called by PHP and the
> "path" starts with a recognized scheme like "mailto:", it may delegate
> the work to the actual mailto: wrapper. But this is just a workaround as
> it is supposed to handle resources on the local filesystem only.
>
> I understand that this behavior is probably caused by
> fopen('some:file.dat'); being mostly used to open a file that has a
> column character in its name and located in the current working
> directory (: character is not allowed in file names on windows, I
> guess). It simply demonstrates once again a problem that may arise with
> the default implicit file:// scheme in URI's.
>
> Anyway, I'm still posting to read your thoughts on this. Maybe someone
> will see another solution than the workaround I explained above.
>
> Thank you!
>
> Julien.

you can also use a wrapper around stream_wrapper_register()!! hee hee

in the end, the usefulness of this kind of statement is surely pretty
small - well my imagination is limited I suppose, can it really be
called a "stream protocol"?
fopen('mailto:u...@domain.com', 'w');
stream_wrapper_register_even_the_fake_ones( $p, $m='r' )
{
//if first 7 chars are 'mailto',
//{ replace
//mailto: with mailto:// and do it
//stream_wrapper_register(str_replace('mailto:','mailto://',$p, $r);
//}
}

etc blah.

stream_wrapper_register_even_the_fake_ones( 'mailto:blah@blah.com',
'w' );

if you come up with a class that codes for the entire mailto thing
with imap support and so on please send it along, it would be useful I
guess

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация