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
checkRequirements($element)

Checks authorization.

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

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 283
protected void startup()

Return Value

void

at line 293
protected void beforeRender()

Common render method.

Return Value

void

at line 302
protected void afterRender()

Common render method.

Return Value

void

at line 310
protected void shutdown(IResponse $response)

Parameters

IResponse $response

Return Value

void

at line 318
void checkRequirements($element)

Checks authorization.

Parameters

$element

Return Value

void

at line 334
void detectedCsrf()

This method will be called when CSRF is detected.

Return Value

void

at line 346
void processSignal()

Return Value

void

Exceptions

BadSignalException

at line 370
final array|null getSignal()

Returns pair signal receiver and name.

Return Value

array|null

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

Checks if the signal receiver is the given one.

Parameters

$component
$signal

Return Value

bool

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

Returns current action name.

Parameters

bool $fullyQualified

Return Value

string

at line 419
void changeAction(string $action)

Changes current action.

Parameters

string $action

Return Value

void

at line 428
final string getView()

Returns current view.

Return Value

string

at line 438
Presenter setView(string $view)

Changes current view. Any name is allowed.

Parameters

string $view

Return Value

Presenter

at line 449
final string|bool getLayout()

Returns current layout name.

Return Value

string|bool

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

Changes or disables layout.

Parameters

string|bool $layout

Return Value

Presenter

at line 471
void sendTemplate()

Return Value

void

Exceptions

BadRequestException if no template found
AbortException

at line 497
string|null findLayoutTemplateFile()

Finds layout template file name.

Return Value

string|null

at line 520
array formatLayoutTemplateFiles()

Formats layout template file names.

Return Value

array

at line 544
array formatTemplateFiles()

Formats view template file names.

Return Value

array

at line 559
static string formatActionMethod(string $action)

Formats action method name.

Parameters

string $action

Return Value

string

at line 568
static string formatRenderMethod(string $view)

Formats render view method name.

Parameters

string $view

Return Value

string

at line 574
protected ITemplate createTemplate()

Return Value

ITemplate

at line 583
final stdClass getPayload()

Return Value

stdClass

at line 592
bool isAjax()

Is AJAX request?

Return Value

bool

at line 605
void sendPayload()

Sends AJAX payload to the output.

Return Value

void

Exceptions

AbortException

at line 616
void sendJson(mixed $data)

Sends JSON data to the output.

Parameters

mixed $data

Return Value

void

Exceptions

AbortException

at line 629
void sendResponse(IResponse $response)

Sends response and terminates presenter.

Parameters

IResponse $response

Return Value

void

Exceptions

AbortException

at line 640
void terminate()

Correctly terminates presenter.

Return Value

void

Exceptions

AbortException

at line 652
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 670
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 689
final Request|null getLastCreatedRequest()

Returns the last created Request.

Return Value

Request|null

at line 699
final bool getLastCreatedRequestFlag(string $flag)

Returns the last created Request flag.

Parameters

string $flag

Return Value

bool

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

Conditional redirect to canonicalized URI.

Parameters

string $destination
array $args

Return Value

void

Exceptions

AbortException

at line 743
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 763
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 932
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 954
protected string requestToUrl(Request $request, bool $relative = null)

Converts Request to URL.

Parameters

Request $request
bool $relative

Return Value

string

at line 989
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 1076
string storeRequest(string $expiration = '+ 10 minutes')

Stores current request to session.

Parameters

string $expiration

Return Value

string key

at line 1092
void restoreRequest(string $key)

Restores request from session.

Parameters

string $key

Return Value

void

at line 1119
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 1134
protected array getGlobalState(string $forClass = null)

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

Parameters

string $forClass

Return Value

array

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

Saves state informations for next request.

Parameters

array $params
ComponentReflection $reflection

Return Value

void

at line 1214
protected void saveGlobalState()

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

Return Value

void

at line 1286
final array popGlobalParameters(string $id)

Pops parameters for specified component.

Parameters

string $id

Return Value

array

at line 1309
bool hasFlashSession()

Checks if a flash session namespace exists.

Return Value

bool

at line 1320
SessionSection getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

Return Value

SessionSection

at line 1333
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 1362
final Container getContext() deprecated

deprecated

Gets the context.

Return Value

Container

at line 1371
final IRequest getHttpRequest()

Return Value

IRequest

at line 1377
final IResponse getHttpResponse()

Return Value

IResponse

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

Parameters

string $namespace

Return Value

Session|SessionSection

at line 1397
final User getUser()

Return Value

User

at line 1406
final ITemplateFactory getTemplateFactory()

Return Value

ITemplateFactory