Support the optional $flags parameter of stream_wrapper_register()

This is similar to the abandoned pull request #1151.