abstract class Presenter extends Control implements IPresenter

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

Constants

INVALID_LINK_SILENT

bad link handling {@link Presenter::$invalidLinkMode}

INVALID_LINK_WARNING

bad link handling {@link Presenter::$invalidLinkMode}

INVALID_LINK_EXCEPTION

bad link handling {@link Presenter::$invalidLinkMode}

INVALID_LINK_TEXTUAL

bad link handling {@link Presenter::$invalidLinkMode}

PRESENTER_KEY

SIGNAL_KEY

ACTION_KEY

FLASH_KEY

DEFAULT_ACTION

Properties

int $invalidLinkMode
callable[]&(callable(Presenter $onStartup
callable[]&(callable(Presenter $onRender
callable[]&(callable(Presenter $onShutdown
bool $autoCanonicalize
bool $absoluteUrls
string $view
string|bool $layout

Methods

__construct()

No description

Request|null
getRequest()

No description

Presenter|null
getPresenter()

Returns self.

Presenter|null
getPresenterIfExists()

Returns the presenter where this component belongs to.

bool
hasPresenter() deprecated

No description

string
getUniqueId()

Returns a name that uniquely identifies component.

bool
isModuleCurrent(string $module)

No description

run(Request $request)

No description

void
startup()

No description

void
beforeRender()

Common render method.

void
afterRender()

Common render method.

void
shutdown(IResponse $response)

No description

void
detectedCsrf()

This method will be called when CSRF is detected.

void
processSignal()

No description

array|null
getSignal()

Returns pair signal receiver and name.

bool
isSignalReceiver($component, $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.

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.

void
sendTemplate(ITemplate $template = null)

No description

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()

No description

getPayload()

No description

bool
isAjax()

Is AJAX request?

void
sendPayload()

Sends AJAX payload to the output.

void
sendJson(mixed $data)

Sends JSON data to the output.

void
sendResponse(IResponse $response)

Sends response and terminates presenter.

void
terminate()

Correctly terminates presenter.

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

Forward to another presenter or action.

void
redirectUrl(string $url, int $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 $destination = null, array $args = [])

Conditional redirect to canonicalized URI.

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

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

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

Request/URL factory.

static array
parseDestination(string $destination)

Parse destination in format "[//] [[[module:]presenter:]action | signal! | this] [?query] [#fragment]"

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

Converts Request to URL.

static void
argsToParams(string $class, string $method, array $args, array $supplemental = [], array $missing = null)

Converts list of arguments to named parameters.

string
handleInvalidLink(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()

Returns array of persistent components.

array
getGlobalState(string $forClass = null)

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

void
saveState(array $params, ComponentReflection $reflection = null)

Saves state informations for next request.

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.

getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

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

No description

getContext() deprecated

Gets the context.

getHttpRequest()

No description

getHttpResponse()

No description

getSession(string $namespace = null)

No description

getUser()

No description

Details

at line 139
__construct()

at line 145
final Request|null getRequest()

Return Value

Request|null

at line 154
final Presenter|null getPresenter()

Returns self.

Return Value

Presenter|null

at line 160
final Presenter|null getPresenterIfExists()

Returns the presenter where this component belongs to.

Return Value

Presenter|null

at line 167
final bool hasPresenter() deprecated

deprecated

Return Value

bool

at line 176
string getUniqueId()

Returns a name that uniquely identifies component.

Return Value

string

at line 182
bool isModuleCurrent(string $module)

Parameters

string $module

Return Value

bool

at line 192
IResponse run(Request $request)

Parameters

Request $request

Return Value

IResponse

at line 281
protected void startup()

Return Value

void

at line 291
protected void beforeRender()

Common render method.

Return Value

void

at line 300
protected void afterRender()

Common render method.

Return Value

void

at line 308
protected void shutdown(IResponse $response)

Parameters

IResponse $response

Return Value

void

at line 316
void detectedCsrf()

This method will be called when CSRF is detected.

Return Value

void

at line 328
void processSignal()

Return Value

void

Exceptions

BadSignalException

at line 350
final array|null getSignal()

Returns pair signal receiver and name.

Return Value

array|null

at line 360
final bool isSignalReceiver($component, $signal = null)

Checks if the signal receiver is the given one.

Parameters

$component
$signal

Return Value

bool

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

Returns current action name.

Parameters

bool $fullyQualified

Return Value

string

at line 397
void changeAction(string $action)

Changes current action.

Parameters

string $action

Return Value

void

at line 406
final string getView()

Returns current view.

Return Value

string

at line 416
Presenter setView(string $view)

Changes current view. Any name is allowed.

Parameters

string $view

Return Value

Presenter

at line 427
final string|bool getLayout()

Returns current layout name.

Return Value

string|bool

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

Changes or disables layout.

Parameters

string|bool $layout

Return Value

Presenter

at line 448
void sendTemplate(ITemplate $template = null)

Parameters

ITemplate $template

Return Value

void

Exceptions

AbortException

at line 474
string|null findLayoutTemplateFile()

Finds layout template file name.

Return Value

string|null

at line 497
array formatLayoutTemplateFiles()

Formats layout template file names.

Return Value

array

at line 521
array formatTemplateFiles()

Formats view template file names.

Return Value

array

at line 536
static string formatActionMethod(string $action)

Formats action method name.

Parameters

string $action

Return Value

string

at line 545
static string formatRenderMethod(string $view)

Formats render view method name.

Parameters

string $view

Return Value

string

at line 554
protected ITemplate createTemplate()

Return Value

ITemplate

at line 564
final stdClass getPayload()

Return Value

stdClass

at line 573
bool isAjax()

Is AJAX request?

Return Value

bool

at line 586
void sendPayload()

Sends AJAX payload to the output.

Return Value

void

Exceptions

AbortException

at line 597
void sendJson(mixed $data)

Sends JSON data to the output.

Parameters

mixed $data

Return Value

void

Exceptions

AbortException

at line 610
void sendResponse(IResponse $response)

Sends response and terminates presenter.

Parameters

IResponse $response

Return Value

void

Exceptions

AbortException

at line 621
void terminate()

Correctly terminates presenter.

Return Value

void

Exceptions

AbortException

at line 633
void forward(string|Request $destination, array|mixed $args = [])

Forward to another presenter or action.

Parameters

string|Request $destination
array|mixed $args

Return Value

void

Exceptions

AbortException

at line 649
void redirectUrl(string $url, int $httpCode = null)

Redirect to another URL and ends presenter execution.

Parameters

string $url
int $httpCode

Return Value

void

Exceptions

AbortException

at line 668
final Request|null getLastCreatedRequest()

Returns the last created Request.

Return Value

Request|null

at line 678
final bool getLastCreatedRequestFlag(string $flag)

Returns the last created Request flag.

Parameters

string $flag

Return Value

bool

at line 688
void canonicalize(string $destination = null, array $args = [])

Conditional redirect to canonicalized URI.

Parameters

string $destination
array $args

Return Value

void

Exceptions

AbortException

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

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

Parameters

string|int|DateTimeInterface $lastModified
string $etag strong entity tag validator
string $expire like '20 minutes'

Return Value

void

Exceptions

AbortException

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

Request/URL factory.

Parameters

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

Return Value

string|null URL

Exceptions

InvalidLinkException

at line 901
static array parseDestination(string $destination)

Parse destination in format "[//] [[[module:]presenter:]action | signal! | this] [?query] [#fragment]"

Parameters

string $destination

Return Value

array

Exceptions

InvalidLinkException

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

Converts Request to URL.

Parameters

Request $request
bool $relative

Return Value

string

at line 958
static void argsToParams(string $class, string $method, array $args, array $supplemental = [], array $missing = null)

Converts list of arguments to named parameters.

Parameters

string $class
string $method
array $args
array $supplemental
array $missing

Return Value

void

Exceptions

InvalidLinkException

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

Parameters

InvalidLinkException $e

Return Value

string

Exceptions

InvalidLinkException

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

Stores current request to session.

Parameters

string $expiration

Return Value

string key

at line 1048
void restoreRequest(string $key)

Restores request from session.

Parameters

string $key

Return Value

void

at line 1075
static array getPersistentComponents()

Returns array of persistent components.

This default implementation detects components by class-level annotation @persistent(cmp1, cmp2).

Return Value

array

at line 1084
protected array getGlobalState(string $forClass = null)

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

Parameters

string $forClass

Return Value

array

at line 1155
void saveState(array $params, ComponentReflection $reflection = null)

Saves state informations for next request.

Parameters

array $params
ComponentReflection $reflection

Return Value

void

at line 1164
protected void saveGlobalState()

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

Return Value

void

at line 1236
final array popGlobalParameters(string $id)

Pops parameters for specified component.

Parameters

string $id

Return Value

array

at line 1259
bool hasFlashSession()

Checks if a flash session namespace exists.

Return Value

bool

at line 1270
SessionSection getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

Return Value

SessionSection

at line 1283
final injectPrimary(Container|null $context, IPresenterFactory|null $presenterFactory, Router|null $router, IRequest $httpRequest, IResponse $httpResponse, Session|null $session = null, User|null $user = null, ITemplateFactory|null $templateFactory = null)

Parameters

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

at line 1305
Container getContext() deprecated

deprecated

Gets the context.

Return Value

Container

at line 1315
final IRequest getHttpRequest()

Return Value

IRequest

at line 1321
final IResponse getHttpResponse()

Return Value

IResponse

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

Parameters

string $namespace

Return Value

Session|SessionSection

at line 1339
final User getUser()

Return Value

User

at line 1348
final ITemplateFactory getTemplateFactory()

Return Value

ITemplateFactory