Packages » Package freeform » Class LocationRewriter

Class LocationRewriter

Declaration:
<? interface LocationRewriter ?>

Description:
This interface is used to rewrite the URLs generated by the Location::toURL() method calls. More specifically, the Location::toURL will look up the config option locationRewriter of the freeform package and will call its LocationRewriter::rewrite() passing itself as the parameter. If this config option is unspecified, then Location objects will return standard URL. This feature is useful when used in combination with your web server URL rewrite engine (like Apache's mod_rewrite). You can create rules that will map rewritten URLs to real ones and write your own LocationRewriter to force Locations to create rewritten URLs. Please note that while the LocationRewriter::rewrite() method must return the absolute URL (including the protocol, host, port and absolute path), the LocationRewriter::decode() method acts on the query string only, which is passed as a single parameter.

Authors:
  • Dennis Popel

Methods:
  • decode()
    This method is called from Request::parseHTTP() method to decode the rewritten URLs as received from the remote user. This method should decode URLs only if the web server doesn't do this itself; owherwise this method can safely return the $_GET array.

    Note: this method is called for GET requests only as there is no way to rewrite POST requests
  • rewrite()
    This method will be called by the Location::toURL() to return the rewritten URL, as it will appear in the browser. This method should return the fully-qualified URL, including protocol, host port and path of the rewritten URL.
    Note: this method cannot call the Location::toURL() method; to retrieve the default URL of a location, the Location::rewrite() static method should be called instead.