abstract class Presenter extends Control implements IPresenter

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

Constants

INVALID_LINK_SILENT

bad link handling Presenter::$invalidLinkMode

INVALID_LINK_WARNING

bad link handling Presenter::$invalidLinkMode

INVALID_LINK_EXCEPTION

bad link handling Presenter::$invalidLinkMode

INVALID_LINK_TEXTUAL

bad link handling Presenter::$invalidLinkMode

internal PRESENTER_KEY

internal SIGNAL_KEY

internal ACTION_KEY

internal FLASH_KEY

internal DEFAULT_ACTION

Properties

int $invalidLinkMode
$onStartup
$onRender
$onShutdown
bool $autoCanonicalize
bool $absoluteUrls
string $view
string|bool $layout
Request read-only $request
string read-only $action
stdClass read-only $payload
Container read-only $context
Session read-only $session
User read-only $user

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(Response $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|string $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(Template|null $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

string|null
formatTemplateClass()

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

Request/URL factory.

static array
parseDestination(string $destination)

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

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

Converts Request to URL.

static void
argsToParams(string $class, string $method, array $args, array $supplemental = [], array|null $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|null $forClass = null)

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

void
saveState(array $params, ComponentReflection|null $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.

SessionSection
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, TemplateFactory|null $templateFactory = null)

No description

Container
getContext() deprecated

Gets the context.

IRequest
getHttpRequest()

No description

IResponse
getHttpResponse()

No description

Session|SessionSection
getSession(string|null $namespace = null)

No description

User
getUser()

No description

Details

at line 140
__construct()

No description

at line 146
final Request|null getRequest()

No description

Return Value

Request|null

at line 155
final Presenter|null getPresenter()

Returns self.

Return Value

Presenter|null

at line 161
final Presenter|null getPresenterIfExists()

Returns the presenter where this component belongs to.

Return Value

Presenter|null

at line 168
final bool hasPresenter() deprecated

deprecated

No description

Return Value

bool

at line 177
string getUniqueId()

Returns a name that uniquely identifies component.

Return Value

string

at line 183
bool isModuleCurrent(string $module)

No description

Parameters

string $module

Return Value

bool

at line 193
Response run(Request $request)

No description

Parameters

Request $request

Return Value

Response

at line 281
protected void startup()

No description

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(Response $response)

No description

Parameters

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

No description

Return Value

void

Exceptions

BadSignalException

at line 352
final array|null getSignal()

Returns pair signal receiver and name.

Return Value

array|null

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

Checks if the signal receiver is the given one.

Parameters

Component|string $component
$signal

Return Value

bool

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

Returns current action name.

Parameters

bool $fullyQualified

Return Value

string

at line 402
void changeAction(string $action)

Changes current action.

Parameters

string $action

Return Value

void

at line 411
final string getView()

Returns current view.

Return Value

string

at line 421
Presenter setView(string $view)

Changes current view. Any name is allowed.

Parameters

string $view

Return Value

Presenter

at line 432
final string|bool getLayout()

Returns current layout name.

Return Value

string|bool

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

Changes or disables layout.

Parameters

string|bool $layout

Return Value

Presenter

at line 454
void sendTemplate(Template|null $template = null)

No description

Parameters

Template|null $template

Return Value

void

Exceptions

AbortException

at line 480
string|null findLayoutTemplateFile()

internal  
 

Finds layout template file name.

Return Value

string|null

at line 505
array formatLayoutTemplateFiles()

Formats layout template file names.

Return Value

array

at line 531
array formatTemplateFiles()

Formats view template file names.

Return Value

array

at line 546
static string formatActionMethod(string $action)

Formats action method name.

Parameters

string $action

Return Value

string

at line 555
static string formatRenderMethod(string $view)

Formats render view method name.

Parameters

string $view

Return Value

string

at line 564
protected Template createTemplate()

No description

Return Value

Template

at line 573
string|null formatTemplateClass()

No description

Return Value

string|null

at line 584
final stdClass getPayload()

No description

Return Value

stdClass

at line 593
bool isAjax()

Is AJAX request?

Return Value

bool

at line 608
void sendPayload()

Sends AJAX payload to the output.

Return Value

void

Exceptions

AbortException

at line 620
void sendJson(mixed $data)

Sends JSON data to the output.

Parameters

mixed $data

Return Value

void

Exceptions

AbortException

at line 634
void sendResponse(Response $response)

Sends response and terminates presenter.

Parameters

Response $response

Return Value

void

Exceptions

AbortException

at line 646
void terminate()

Correctly terminates presenter.

Return Value

void

Exceptions

AbortException

at line 659
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 678
void redirectUrl(string $url, int|null $httpCode = null)

Redirect to another URL and ends presenter execution.

Parameters

string $url
int|null $httpCode

Return Value

void

Exceptions

AbortException

at line 698
final Request|null getLastCreatedRequest()

internal  
 

Returns the last created Request.

Return Value

Request|null

at line 708
final bool getLastCreatedRequestFlag(string $flag)

internal  
 

Returns the last created Request flag.

Parameters

string $flag

Return Value

bool

at line 719
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 757
void lastModified(string|int|DateTimeInterface $lastModified, string|null $etag = null, string|null $expire = null)

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

Parameters

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

strong entity tag validator

string|null $expire

like '20 minutes'

Return Value

void

Exceptions

AbortException

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

internal  
 

Request/URL factory.

Parameters

Component $component
string $destination

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

array $args
string $mode forward|redirect|link

Return Value

string|null URL

Exceptions

InvalidLinkException

at line 971
static array parseDestination(string $destination)

internal  
 

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

Parameters

string $destination

Return Value

array

Exceptions

InvalidLinkException

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

internal  
 

Converts Request to URL.

Parameters

Request $request
bool|null $relative

Return Value

string

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

internal  
 

Converts list of arguments to named parameters.

Parameters

string $class
string $method
array $args
array $supplemental
array|null $missing arguments

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 1120
string storeRequest(string $expiration = '+ 10 minutes')

Stores current request to session.

Parameters

string $expiration

Return Value

string key

at line 1136
void restoreRequest(string $key)

Restores request from session.

Parameters

string $key

Return Value

void

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

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

Parameters

string|null $forClass

Return Value

array

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

Saves state informations for next request.

Parameters

array $params
ComponentReflection|null $reflection

Return Value

void

at line 1263
protected void saveGlobalState()

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

Return Value

void

at line 1338
final array popGlobalParameters(string $id)

internal  
 

Pops parameters for specified component.

Parameters

string $id

Return Value

array

at line 1361
bool hasFlashSession()

Checks if a flash session namespace exists.

Return Value

bool

at line 1372
SessionSection getFlashSession()

Returns session namespace provided to pass temporary data between redirects.

Return Value

SessionSection

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

No description

Parameters

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

at line 1415
Container getContext() deprecated

deprecated

Gets the context.

Return Value

Container

at line 1426
final IRequest getHttpRequest()

No description

Return Value

IRequest

at line 1432
final IResponse getHttpResponse()

No description

Return Value

IResponse

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

No description

Parameters

string|null $namespace

Return Value

Session|SessionSection

at line 1453
final User getUser()

No description

Return Value

User

at line 1463
final TemplateFactory getTemplateFactory()

No description

Return Value

TemplateFactory