abstract class Presenter extends Control implements IPresenter

Presenter component represents a webpage instance. It converts Request to Response.

Constants

InvalidLinkSilent

bad link handling Presenter::$invalidLinkMode

InvalidLinkWarning

bad link handling Presenter::$invalidLinkMode

InvalidLinkException

bad link handling Presenter::$invalidLinkMode

InvalidLinkTextual

bad link handling Presenter::$invalidLinkMode

internal PresenterKey

internal SignalKey

internal ActionKey

internal FlashKey

internal DefaultAction

deprecated INVALID_LINK_SILENT

deprecated INVALID_LINK_WARNING

deprecated INVALID_LINK_EXCEPTION

deprecated INVALID_LINK_TEXTUAL

deprecated PRESENTER_KEY

deprecated SIGNAL_KEY

deprecated ACTION_KEY

deprecated FLASH_KEY

deprecated DEFAULT_ACTION

Properties

$invalidLinkMode
$onStartup
$onRender
$onShutdown
$autoCanonicalize

automatically call canonicalize()

$absoluteUrls

use absolute Urls or paths?

list<string> deprecated $allowedMethods
stdClass read-only $payload
User read-only $user

Methods

getRequest()

No description

Presenter|null
getPresenter(bool $throw = true)

No description

Presenter|null
getPresenterIfExists() deprecated

No description

bool
hasPresenter() deprecated

No description

string
getUniqueId()

Returns a name that uniquely identifies component.

bool
isModuleCurrent(string $module)

Checks whether the current presenter belongs to the given module.

bool
isForwarded()

Checks whether the current request was forwarded from another presenter or action.

run(Request $request)

No description

void
startup()

Called before action method. Override to run initialization common to all actions.

void
beforeRender()

Called before the view is rendered. Override to set up common template variables.

void
afterRender()

Called after the view is rendered. Override for post-render processing.

void
shutdown(Response $response)

Called after the response is ready. Override for cleanup after request handling.

void
detectedCsrf()

This method will be called when CSRF is detected.

void
checkHttpMethod() deprecated

No description

void
processSignal()

No description

array|null
getSignal()

Returns pair signal receiver and name.

bool
isSignalReceiver(Component|string $component, string|true|null $signal = null)

Checks if the signal receiver is the given one.

string
getAction(bool $fullyQualified = false)

Returns current action name.

void
changeAction(string $action)

Changes current action.

never
switch(string $action)

Switch from current action or render method to another.

string
getView()

Returns current view.

setView(string $view)

Changes current view. Any name is allowed.

string|bool
getLayout()

Returns current layout name.

setLayout(string|bool $layout)

Changes or disables layout.

never
sendTemplate(Template|null $template = null)

No description

void
completeTemplate(Template $template)

Completes template parameters and file before rendering.

string
findTemplateFile()

Finds template file name.

string|null
findLayoutTemplateFile()

Finds layout template file name.

array
formatLayoutTemplateFiles()

Formats layout template file names.

array
formatTemplateFiles()

Formats view template file names.

static string
formatActionMethod(string $action)

Formats action method name.

static string
formatRenderMethod(string $view)

Formats render view method name.

createTemplate(string|null $class = null)

No description

string|null
formatTemplateClass()

No description

getPayload()

No description

bool
isAjax()

Is AJAX request?

never
sendPayload()

Sends AJAX payload to the output.

never
sendJson(mixed $data)

Sends JSON data to the output.

never
sendResponse(Response $response)

Sends response and terminates presenter.

never
terminate()

Correctly terminates presenter.

never
forward(Request $destination, array|mixed $args = [])

Forward to another presenter or action.

never
redirectUrl(string $url, int|null $httpCode = null)

Redirect to another URL and ends presenter execution.

Request|null
getLastCreatedRequest()

Returns the last created Request.

bool
getLastCreatedRequestFlag(string $flag)

Returns the last created Request flag.

void
canonicalize(string|null $destination = null, mixed ...$args)

Conditional redirect to canonicalized URI.

void
lastModified(string|int|DateTimeInterface|null $lastModified, string|null $etag = null, string|null $expire = null)

Attempts to cache the sent entity by its last modification date.

string|null
createRequest(Component $component, string $destination, array $args, string $mode) deprecated

No description

static array
parseDestination(string $destination) deprecated

No description

string
requestToUrl(Request $request, bool|null $relative = null)

No description

string
processInvalidLink(InvalidLinkException $e)

Invalid link handler. Descendant can override this method to change default behaviour.

string
storeRequest(string $expiration = '+ 10 minutes')

Stores current request to session.

void
restoreRequest(string $key)

Restores request from session.

static array
getPersistentComponents()

Descendant can override this method to return the names of custom persistent components.

array
getGlobalState(string|null $forClass = null)

Saves state information for all subcomponents to $this->globalState.

void
saveGlobalState()

Permanently saves state information for all subcomponents to $this->globalState.

array
popGlobalParameters(string $id)

Pops parameters for specified component.

bool
hasFlashSession()

Checks if a flash session namespace exists.

SessionSection
getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

void
injectPrimary(IRequest $httpRequest, IResponse $httpResponse, IPresenterFactory|null $presenterFactory = null, Router|null $router = null, Session|null $session = null, User|null $user = null, TemplateFactory|null $templateFactory = null)

No description

IRequest
getHttpRequest()

No description

IResponse
getHttpResponse()

No description

SessionSection
getSession(string|null $namespace = null)

No description

User
getUser()

No description

getLinkGenerator()

No description

Details

at line 126
final Request getRequest()

No description

Return Value

Request

at line 135
final Presenter|null getPresenter(bool $throw = true)

No description

Parameters

bool $throw

Return Value

Presenter|null

at line 142
final Presenter|null getPresenterIfExists() deprecated

deprecated

No description

Return Value

Presenter|null

at line 149
final bool hasPresenter() deprecated

deprecated

No description

Return Value

bool

at line 158
string getUniqueId()

Returns a name that uniquely identifies component.

Return Value

string

at line 167
bool isModuleCurrent(string $module)

Checks whether the current presenter belongs to the given module.

Parameters

string $module

Return Value

bool

at line 177
bool isForwarded()

Checks whether the current request was forwarded from another presenter or action.

Return Value

bool

at line 186
Response run(Request $request)

No description

Parameters

Request $request

Return Value

Response

at line 293
protected void startup()

Called before action method. Override to run initialization common to all actions.

Return Value

void

at line 303
protected void beforeRender()

Called before the view is rendered. Override to set up common template variables.

Return Value

void

at line 311
protected void afterRender()

Called after the view is rendered. Override for post-render processing.

Return Value

void

at line 319
protected void shutdown(Response $response)

Called after the response is ready. Override for cleanup after request handling.

Parameters

Response $response

Return Value

void

at line 327
void detectedCsrf()

This method will be called when CSRF is detected.

Return Value

void

at line 338
protected void checkHttpMethod() deprecated

deprecated use #[Requires(methods: ...)] to specify allowed methods

No description

Return Value

void

at line 355
void processSignal()

No description

Return Value

void

Exceptions

BadSignalException

at line 380
final array|null getSignal()

Returns pair signal receiver and name.

Return Value

array|null

at line 389
final bool isSignalReceiver(Component|string $component, string|true|null $signal = null)

Checks if the signal receiver is the given one.

Parameters

Component|string $component
string|true|null $signal

Return Value

bool

at line 421
final string getAction(bool $fullyQualified = false)

Returns current action name.

Parameters

bool $fullyQualified

Return Value

string

at line 432
void changeAction(string $action)

Changes current action.

Parameters

string $action

Return Value

void

at line 442
never switch(string $action)

Switch from current action or render method to another.

Parameters

string $action

Return Value

never

at line 451
final string getView()

Returns current view.

Return Value

string

at line 460
Presenter setView(string $view)

Changes current view. Any name is allowed.

Parameters

string $view

Return Value

Presenter

at line 471
final string|bool getLayout()

Returns current layout name.

Return Value

string|bool

at line 480
Presenter setLayout(string|bool $layout)

Changes or disables layout.

Parameters

string|bool $layout

Return Value

Presenter

at line 490
never sendTemplate(Template|null $template = null)

No description

Parameters

Template|null $template

Return Value

never

Exceptions

AbortException

at line 501
protected void completeTemplate(Template $template)

Completes template parameters and file before rendering.

Parameters

Template $template

Return Value

void

at line 515
string findTemplateFile()

Finds template file name.

Return Value

string

at line 533
string|null findLayoutTemplateFile()

internal  
 

Finds layout template file name.

Return Value

string|null

at line 559
array formatLayoutTemplateFiles()

Formats layout template file names.

Return Value

array

at line 596
array formatTemplateFiles()

Formats view template file names.

Return Value

array

at line 619
static string formatActionMethod(string $action)

Formats action method name.

Parameters

string $action

Return Value

string

at line 628
static string formatRenderMethod(string $view)

Formats render view method name.

Parameters

string $view

Return Value

string

at line 639
protected Template createTemplate(string|null $class = null)

No description

Parameters

string|null $class

Return Value

Template

at line 647
string|null formatTemplateClass()

No description

Return Value

string|null

at line 658
final stdClass getPayload()

No description

Return Value

stdClass

at line 667
bool isAjax()

Is AJAX request?

Return Value

bool

at line 681
never sendPayload()

Sends AJAX payload to the output.

Return Value

never

Exceptions

AbortException

at line 691
never sendJson(mixed $data)

Sends JSON data to the output.

Parameters

mixed $data

Return Value

never

Exceptions

AbortException

at line 704
never sendResponse(Response $response)

Sends response and terminates presenter.

Parameters

Response $response

Return Value

never

Exceptions

AbortException

at line 715
never terminate()

Correctly terminates presenter.

Return Value

never

Exceptions

AbortException

at line 726
never forward(Request $destination, array|mixed $args = [])

Forward to another presenter or action.

Parameters

Request $destination
array|mixed $args

Return Value

never

Exceptions

AbortException

at line 744
never redirectUrl(string $url, int|null $httpCode = null)

Redirect to another URL and ends presenter execution.

Parameters

string $url
int|null $httpCode

Return Value

never

Exceptions

AbortException

at line 764
final Request|null getLastCreatedRequest()

internal  
 

Returns the last created Request.

Return Value

Request|null

at line 774
final bool getLastCreatedRequestFlag(string $flag)

internal  
 

Returns the last created Request flag.

Parameters

string $flag

Return Value

bool

at line 785
void canonicalize(string|null $destination = null, mixed ...$args)

Conditional redirect to canonicalized URI.

Parameters

string|null $destination
mixed ...$args

Return Value

void

Exceptions

AbortException

at line 822
void lastModified(string|int|DateTimeInterface|null $lastModified, string|null $etag = null, string|null $expire = null)

Attempts to cache the sent entity by its last modification date.

Parameters

string|int|DateTimeInterface|null $lastModified
string|null $etag

strong entity tag validator

string|null $expire

like '20 minutes'

Return Value

void

Exceptions

AbortException

at line 843
protected string|null createRequest(Component $component, string $destination, array $args, string $mode) deprecated

deprecated @internal

No description

Parameters

Component $component
string $destination
array $args
string $mode

Return Value

string|null

at line 855
static array parseDestination(string $destination) deprecated

deprecated @internal

No description

Parameters

string $destination

Return Value

array

at line 863
protected string requestToUrl(Request $request, bool|null $relative = null)

No description

Parameters

Request $request
bool|null $relative

Return Value

string

Invalid link handler. Descendant can override this method to change default behaviour.

Parameters

InvalidLinkException $e

Return Value

string

Exceptions

InvalidLinkException

at line 895
string storeRequest(string $expiration = '+ 10 minutes')

Stores current request to session.

Parameters

string $expiration

Return Value

string

at line 911
void restoreRequest(string $key)

Restores request from session.

Parameters

string $key

Return Value

void

at line 941
static array getPersistentComponents()

Descendant can override this method to return the names of custom persistent components.

Return Value

array

at line 952
array getGlobalState(string|null $forClass = null)

Saves state information for all subcomponents to $this->globalState.

Parameters

string|null $forClass

Return Value

array

at line 1027
protected void saveGlobalState()

Permanently saves state information for all subcomponents to $this->globalState.

Return Value

void

at line 1105
final array popGlobalParameters(string $id)

internal  
 

Pops parameters for specified component.

Parameters

string $id

Return Value

array

at line 1128
bool hasFlashSession()

Checks if a flash session namespace exists.

Return Value

bool

at line 1139
SessionSection getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

Return Value

SessionSection

at line 1153
final void injectPrimary(IRequest $httpRequest, IResponse $httpResponse, IPresenterFactory|null $presenterFactory = null, Router|null $router = null, Session|null $session = null, User|null $user = null, TemplateFactory|null $templateFactory = null)

No description

Parameters

IRequest $httpRequest
IResponse $httpResponse
IPresenterFactory|null $presenterFactory
Router|null $router
Session|null $session
User|null $user
TemplateFactory|null $templateFactory

Return Value

void

at line 1179
final IRequest getHttpRequest()

No description

Return Value

IRequest

at line 1185
final IResponse getHttpResponse()

No description

Return Value

IResponse

at line 1194
final SessionSection getSession(string|null $namespace = null)

No description

Parameters

string|null $namespace

Return Value

SessionSection

at line 1206
final User getUser()

No description

Return Value

User

at line 1212
final TemplateFactory getTemplateFactory()

No description

Return Value

TemplateFactory

at line 1218
final protected LinkGenerator getLinkGenerator()

No description

Return Value

LinkGenerator