\Dewdrop\Admin\ResponseHelperStandard

The response helper object gets injected into a page's process() method and allows the page author to perform redirects or set status messages.

The response helper does not perform any actions until its execute() method is called -- generally by the component object that dispatched the page in the first place. This delayed execution of the actions defined during your page's process method makes it easier to write unit tests for your page.

For example, after writing a test that supplies valid data to a form, you could test to see if the page would redirect like you expect it to by calling this object's hasRedirectUrl() method and neglecting to call its execute() method at all.

Summary

Methods
Properties
Constants
__construct()
setSuccessMessage()
redirectToAdminPage()
redirectToUrl()
execute()
executeCallbacks()
executeSuccessMessage()
executeRedirect()
hasRedirectUrl()
hasSuccessMessage()
willRun()
willShortCircuitResponse()
run()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$page
$successMessage
$redirectUrl
$callbacks
$redirector
$session
N/A

Properties

$page

$page : \Dewdrop\Admin\Page\PageAbstract

The page that created this helper. The page object is used for creating URLs, etc.

Type

\Dewdrop\Admin\Page\PageAbstract

$successMessage

$successMessage : string

A success message that you would like to be displayed to the user on the next page load. (The message is typically displayed by the WpAdminNotice view helper.)

Type

string

$redirectUrl

$redirectUrl : string

The URL you'd like to redirect to after the process() method.

Type

string

$callbacks

$callbacks : array

Callbacks to run as part of executing the response

Type

array

$redirector

$redirector : callable

A callable that can be used to execute the queued redirect.

Redirecting varies quite a bit between WP and Silex. In WP, it's just a normal function. In Silex, the redirect method returns a response, which must then be returned from the controller.

Type

callable

$session

$session : \Dewdrop\Session

A Dewdrop\Session object that can be used to store success messages across redirects.

Type

\Dewdrop\Session

Methods

__construct()

__construct(\Dewdrop\Admin\Page\PageAbstract  $page, callable  $redirector, \Dewdrop\Session  $session = null) 

Create a new ResponseHelper, generally kicked off by a page class in its createResponseHelper() method.

Parameters

\Dewdrop\Admin\Page\PageAbstract $page
callable $redirector
\Dewdrop\Session $session

setSuccessMessage()

setSuccessMessage(  $message) : \Dewdrop\Admin\ResponseHelper\Standard

Set a success message you'd like displayed on the next request.

Parameters

$message

string

Returns

\Dewdrop\Admin\ResponseHelper\Standard

redirectToAdminPage()

redirectToAdminPage(string  $page, array  $params = array()) : \Dewdrop\Admin\ResponseHelper\Standard

Set the redirect URL to a page in the current component.

The page parameter should be supplied with capitalization matching the file and class name (e.g. "Index", not "index").

Parameters

string $page
array $params

Returns

\Dewdrop\Admin\ResponseHelper\Standard

redirectToUrl()

redirectToUrl(string  $url) : $this

Redirect to an arbitrary URL rather than a page in the same admin component.

Parameters

string $url

Returns

$this

execute()

execute() : boolean

Perform any actions that have been setup by the page's process() method. In a testing environment, you'd likely skip this method to avoid "exit" following redirects, etc.

Returns

boolean

executeCallbacks()

executeCallbacks() : \Dewdrop\Admin\ResponseHelper\Standard

Run any queued callbacks. Normally, this will just be called by the execute() method, but sometimes in testing, you may want to selectively execute portions of the response payload.

Returns

\Dewdrop\Admin\ResponseHelper\Standard

hasRedirectUrl()

hasRedirectUrl() : boolean

Check whether a redirect URL has been set. Can be useful in testing to see if validation succeeded and a redirect was set.

Returns

boolean

hasSuccessMessage()

hasSuccessMessage() : boolean

Check whether a success message has been set. Can be useful in testing to see if validation succeeded and a success message was added.

Returns

boolean

willRun()

willRun(string  $callbackLabel) : boolean

Check to see if the given callback label will run if the response is executed.

Parameters

string $callbackLabel

Returns

boolean

willShortCircuitResponse()

willShortCircuitResponse() : boolean

Check to see if the executing the queued actions will short circuit the response.

Returns

boolean

run()

run(string  $label, mixed  $callback = null) : \Dewdrop\Admin\ResponseHelper\Standard

Schedule a callback to run while executing the response.

If the $callback parameter is null, then the $label parameter will be used for both the label and the callback and the callback will be assumed to be a method on the current page.

Parameters

string $label
mixed $callback

Returns

\Dewdrop\Admin\ResponseHelper\Standard