phpday 2027 - Call for Papers

The Yaf_Dispatcher class

(Yaf >=1.0.0)

Introduction

Yaf_Dispatcher purpose is to initialize the request environment, route the incoming request, and then dispatch any discovered actions; it aggregates any responses and returns them when the process is complete.

Yaf_Dispatcher also implements the Singleton pattern, meaning only a single instance of it may be available at any given time. This allows it to also act as a registry on which the other objects in the dispatch process may draw.

Class synopsis

final class Yaf_Dispatcher {
/* Properties */
protected $_router;
protected $_view;
protected $_request;
protected $_plugins;
protected static $_instance;
protected $_auto_render;
protected $_default_module;
protected $_default_action;
/* Methods */
private function __construct()
public function autoRender(?bool $flag = null): Yaf_Dispatcher|bool
public function catchException(?bool $flag = null): Yaf_Dispatcher|bool
public function disableView(): ?Yaf_Dispatcher
public function enableView(): ?Yaf_Dispatcher
public function flushInstantly(?bool $flag = null): Yaf_Dispatcher|bool
public function getApplication(): ?Yaf_Application
public function getDefaultAction(): ?string
public function getDefaultController(): ?string
public function getDefaultModule(): ?string
public static function getInstance(): ?Yaf_Dispatcher
public function getRouter(): ?Yaf_Router
public function initView(string $templates_dir, ?array $options = null): Yaf_View_Interface|null|false
public function returnResponse(bool $flag = false): Yaf_Dispatcher|bool
public function setDefaultAction(string $action): Yaf_Dispatcher|null|false
public function setDefaultController(string $controller): Yaf_Dispatcher|null|false
public function setDefaultModule(string $module): Yaf_Dispatcher|null|false
public function setErrorHandler(mixed $callback, int $error_types = 0): Yaf_Dispatcher|null|false
public function throwException(?bool $flag = null): Yaf_Dispatcher|bool
}

Properties

_router

The Yaf_Router instance used by the dispatcher to route requests.

_view

The Yaf_View_Interface implementation used to render views, lazily initialized on first dispatch.

_request

The request object being dispatched.

_plugins

The list of plugins registered with Yaf_Dispatcher::registerPlugin().

_instance

Static reference to the single dispatcher instance.

_auto_render

Whether the dispatcher automatically renders the view after dispatching. Defaults to true.

_return_response

Whether Yaf_Application::run() returns the response object instead of sending it directly. Defaults to false.

_instantly_flush

Whether the response body is flushed immediately when it is set. Defaults to true.

_default_module

The default module name, from the application.dispatcher.defaultModule configuration entry.

_default_controller

The default controller name, from the application.dispatcher.defaultController configuration entry.

_default_action

The default action name, from the application.dispatcher.defaultAction configuration entry.

Table of Contents

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top