Skip to content

Psr7 Compatibility

Trevor Rowbotham edited this page Aug 1, 2019 · 1 revision

Adding Psr7 support seems like a no-brainer, however, there are a number of compatibility issues that concern me. If you have input about compatibility with Psr7, please feel free to open an issue and share your thoughts.

Keep in mind that the URL object from the WHATWG URL standard MUST resolve to an absolute URL.

Potential problems

  1. Psr7 requires strict compliance with RFC 3986. This technically makes the WHATWG URL standard incompatible, as it is an amalgam of RFC 3986, RFC 3987 and other rules, with the goal of superseeding both RFC 3986 and RFC 3987.

  2. Psr7's UriInterface states that it MUST be treated as an immutable object, whereas the WHATWG URL object is treated as a mutable object.

  3. UriInterface::withScheme() states that passing the empty string is equivilent to removing the scheme. The WHATWG spec only allows schemes to be changed to another valid scheme, not removed.

  4. Like the above, UriInterface::withHost() states that passing the empty string is equivilent to removing the host. The URL object only allows the removal of the host if the associated scheme is not http, https, ftp, gopher, ws, or wss.

Possible solutions

    • We accept the WHATWG URL standard as the defacto standard for parsing URLs and forget about strict compliance with RFC 3986.
    • We jump through a bunch of hoops to transform the parsed data to be RFC 3986 compliant.
    • We slap the UriInterface on the URL object and accept that the object can be treated as both mutable and immutable.
    • We create a separate concrete class that is always treated as immutable.
    • We throw an \InvalidArgumentException whenever the empty string is passed.
    • We throw an \InvalidArgumentException whenever the empty string causes the parser to fail.
Clone this wiki locally