Better cleanup of registered streams

This commit is contained in:
Robin Appelman 2014-07-31 01:06:38 +02:00
commit 99ecfc5287
4 changed files with 26 additions and 7 deletions

View file

@ -116,7 +116,12 @@ class IteratorDirectory implements Directory {
throw new \BadMethodCallException('$source should be an Iterator or array');
}
stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
$wrapped = opendir('iterator://', $context);
try {
$wrapped = opendir('iterator://', $context);
} catch (\BadMethodCallException $e) {
stream_wrapper_unregister('iterator');
throw $e;
}
stream_wrapper_unregister('iterator');
return $wrapped;
}