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[] $onStartup
callable[] $onShutdown
bool $autoCanonicalize
bool $absoluteUrls
string $view
string|bool $layout

Methods

__construct()

No description

Request|null
getRequest()

No description

Presenter|null
getPresenter()

Returns self.

bool
hasPresenter()

Returns whether there is a presenter.

string
getUniqueId()

Returns a name that uniquely identifies component.

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 $context = null, IPresenterFactory $presenterFactory = null, Router $router = null, IRequest $httpRequest, IResponse $httpResponse, Session $session = null, User $user = null, ITemplateFactory $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 136
__construct()

at line 142
final Request|null getRequest()

Return Value

Request|null

at line 151
final Presenter|null getPresenter()

Returns self.

Return Value

Presenter|null

at line 157
final bool hasPresenter()

Returns whether there is a presenter.

Return Value

bool

at line 166
string getUniqueId()

Returns a name that uniquely identifies component.

Return Value

string

at line 175
IResponse run(Request $request)

Parameters

Request $request

Return Value

IResponse

at line 265
protected void startup()

Return Value

void

at line 275
protected void beforeRender()

Common render method.

Return Value

void

at line 284
protected void afterRender()

Common render method.

Return Value

void

at line 292
protected void shutdown(IResponse $response)

Parameters

IResponse $response

Return Value

void

at line 300
void checkRequirements($element)

Checks authorization.

Parameters

$element

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 449
void sendTemplate()

Return Value

void

Exceptions

BadRequestException if no template found
AbortException

at line 475
string|null findLayoutTemplateFile()

Finds layout template file name.

Return Value

string|null

at line 498
array formatLayoutTemplateFiles()

Formats layout template file names.

Return Value

array

at line 522
array formatTemplateFiles()

Formats view template file names.

Return Value

array

at line 537
static string formatActionMethod(string $action)

Formats action method name.

Parameters

string $action

Return Value

string

at line 546
static string formatRenderMethod(string $view)

Formats render view method name.

Parameters

string $view

Return Value

string

at line 552
protected ITemplate createTemplate()

Return Value

ITemplate

at line 561
final stdClass getPayload()

Return Value

stdClass

at line 570
bool isAjax()

Is AJAX request?

Return Value

bool

at line 583
void sendPayload()

Sends AJAX payload to the output.

Return Value

void

Exceptions

AbortException

at line 594
void sendJson(mixed $data)

Sends JSON data to the output.

Parameters

mixed $data

Return Value

void

Exceptions

AbortException

at line 607
void sendResponse(IResponse $response)

Sends response and terminates presenter.

Parameters

IResponse $response

Return Value

void

Exceptions

AbortException

at line 618
void terminate()

Correctly terminates presenter.

Return Value

void

Exceptions

AbortException

at line 630
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 646
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 665
final Request|null getLastCreatedRequest()

Returns the last created Request.

Return Value

Request|null

at line 675
final bool getLastCreatedRequestFlag(string $flag)

Returns the last created Request flag.

Parameters

string $flag

Return Value

bool

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

Conditional redirect to canonicalized URI.

Parameters

string $destination
array $args

Return Value

void

Exceptions

AbortException

at line 713
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 733
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 898
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 920
protected string requestToUrl(Request $request, bool $relative = null)

Converts Request to URL.

Parameters

Request $request
bool $relative

Return Value

string

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

Stores current request to session.

Parameters

string $expiration

Return Value

string key

at line 1045
void restoreRequest(string $key)

Restores request from session.

Parameters

string $key

Return Value

void

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

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

Parameters

string $forClass

Return Value

array

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

Saves state informations for next request.

Parameters

array $params
ComponentReflection $reflection

Return Value

void

at line 1157
protected void saveGlobalState()

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

Return Value

void

at line 1229
final array popGlobalParameters(string $id)

Pops parameters for specified component.

Parameters

string $id

Return Value

array

at line 1252
bool hasFlashSession()

Checks if a flash session namespace exists.

Return Value

bool

at line 1263
SessionSection getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

Return Value

SessionSection

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

Parameters

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

at line 1298
final Container getContext() deprecated

deprecated

Gets the context.

Return Value

Container

at line 1307
final IRequest getHttpRequest()

Return Value

IRequest

at line 1313
final IResponse getHttpResponse()

Return Value

IResponse

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

Parameters

string $namespace

Return Value

Session|SessionSection

at line 1331
final User getUser()

Return Value

User

at line 1340
final ITemplateFactory getTemplateFactory()

Return Value

ITemplateFactory