php8.5
Home/ Manual/ yaf / yaf_dispatcher/ Yaf_Dispatcher::setResponse

Yaf_Dispatcher::setResponse

PHP function Edit on GitHub ✎

(Yaf >=3.2.2)

Set the response object

Description

Yaf_Dispatcher::setResponse(Yaf_Response_Abstract $response): Yaf_Dispatcher|null

Set the response object used by the dispatcher. This allows using a custom response implementation instead of the built-in ones.

Parameters

response

A Yaf_Response_Abstract instance.

Return Values

Returns the Yaf_Dispatcher object itself on success, or null if the application is not initialized.

Examples

Yaf_Dispatcher::setResponse example

php
<?php
class ApiResponse extends Yaf_Response_Http
{
    public function response()
    {
        header("Content-Type: application/json");
        parent::response();
    }
}

$app = new Yaf_Application(dirname(__FILE__) . "/conf/application.ini");

Yaf_Dispatcher::getInstance()->setResponse(new ApiResponse());

$app->run();
?>

See Also

  • Yaf_Dispatcher::getResponse
  • Yaf_Dispatcher::setRequest

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