php8.5
Home/ Manual/ yaf / yaf_plugin_abstract/ Yaf_Plugin_Abstract::routerStartup

Yaf_Plugin_Abstract::routerStartup

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Hook before routing

Description

Yaf_Plugin_Abstract::routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void

This hook is triggered right before the request is routed. It is the earliest hook in the dispatch flow, so it is usually used for URL rewriting or for routing decisions that must happen before Yaf_Router::route runs.

Parameters

request

The Yaf_Request_Abstract instance being dispatched.

response

The Yaf_Response_Abstract instance.

Return Values

No value is returned.

Examples

Yaf_Plugin_Abstract::routerStartup example

php
<?php
class RewritePlugin extends Yaf_Plugin_Abstract
{
    public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
    {
        /* rewrite "/about" style URIs to "/page/about" before
         * routing runs */
        $uri = $request->getRequestUri();
        if (preg_match("#^/[a-z]+$#", $uri)) {
            $request->setRequestUri("/page" . $uri);
        }
    }
}

/* plugins are registered in the bootstrap */
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initPlugin(Yaf_Dispatcher $dispatcher)
    {
        $dispatcher->registerPlugin(new RewritePlugin());
    }
}
?>

See Also

  • Yaf_Plugin_Abstract::routerShutdown
  • Yaf_Plugin_Abstract::dispatchLoopStartup
  • Yaf_Plugin_Abstract::preDispatch
  • Yaf_Plugin_Abstract::postDispatch
  • Yaf_Plugin_Abstract::dispatchLoopShutdown
  • Yaf_Plugin_Abstract::preResponse

Source: reference/yaf/yaf_plugin_abstract/routerstartup.xml · from the official PHP manual (php/doc-en)