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

Yaf_Plugin_Abstract::preResponse

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Hook before the response is sent

Description

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

This hook is intended to be triggered before the response is sent to the client.

Warning

As of this version this hook is never called: it is registered on Yaf_Plugin_Abstract but not wired into the dispatch flow. Overriding it has no effect.

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::preResponse example

php
<?php
class MinifyPlugin extends Yaf_Plugin_Abstract
{
    public function preResponse(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
    {
        /* meant to minify the body right before it is sent; note
         * that, as of this version, this hook is never actually
         * called */
        $response->setBody(
            preg_replace("/>\s+</", "><", $response->getBody())
        );
    }
}

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

See Also

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

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