xp-framework/rfc — Issue #180: UrlInputStream
Author: thekid
Created: 2011-10-17 16:03:26+00:00
State: open
Labels: draft, framework

Scope of Change
====
A new class `io.streams.UrlInputStream` will be created. This class
will serve as a factory for other streams depending on the protocol passed
in.

Rationale
====
Easy and unified URL handling.

Functionality
====

Example
----
This has to be implemented in user code wanting to accept URLs as input
and then read from them using streams:

```php
getScheme()) {
case 'file': {
return new FileInputStream(new File($url->getPath()));
}

case 'http': case 'https': {
$c= new HttpConnection($url);
return new HttpInputStream($c->get($url->getPath(), $url->getParams()));
}

case 'ftp': {
$c= new FtpConnection($url);
return $c->connect()->rootDir()->getFile($url->getPath())->getInputStream();
}

default: {
throw new IllegalArgumentException('Cannot stream for protocol '.$url->getScheme());
}
}
}
?>
```

New API
----
The new class will include the above factory sourcecode:

```php

```

Security considerations
====
None.

Speed impact
====
None.

Dependencies
====
None.

Related documents
====
None.