Class Controller
A route controller.
Accessing the application's properties
The class tries to retrieve undefined properties from the application, so the following code
yields the same results:
<?php
$this ->app->models
$this ->models
But because request
is defined by the controller the following code might not yield the same
results:
<?php
$this ->app->request
$this ->request
ICanBoogie\Prototyped
┗
ICanBoogie\Routing\Controller
Methods summary
protected
get_name ( void )
: string|null
Return the name of the controller, extracted from its class name.
Return the name of the controller, extracted from its class name.
Returns
string|null
The underscored name of the controller, or null
if it cannot be
extracted.
protected
get_request ( void )
: ICanBoogie\HTTP\Request
Returns
ICanBoogie\HTTP\Request
protected
lazy_get_response ( void )
: ICanBoogie\HTTP\Response
Returns
ICanBoogie\HTTP\Response
final public
__invoke ( ICanBoogie\HTTP\Request $request
)
: ICanBoogie\HTTP\Response|mixed
Controls the route and returns a response.
Controls the route and returns a response.
The response is obtained by invoking action()
. When the result is a ICanBoogie\HTTP\Response
instance it is returned as is, when the $response
property has been initialized the result
is used as its body and the response is returned, otherwise the result is returned as is.
The ICanBoogie\Routing\Controller::action:before
event of class
ICanBoogie\Routing\Controller\BeforeActionEvent
is fired before invoking action()
, the
ICanBoogie\Routing\Controller::action:before
event of class
ICanBoogie\Routing\Controller\ActionEvent
is fired after.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
abstract protected
action ( ICanBoogie\HTTP\Request $request
)
: ICanBoogie\HTTP\Response|mixed
Performs the proper action for the request.
Performs the proper action for the request.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
public
redirect ( ICanBoogie\Routing\Route
|string $url
, integer $status
= Status::FOUND , array $headers
= [] )
: ICanBoogie\HTTP\RedirectResponse
Redirects the request.
Parameters
$url
The URL to redirect the request to.
$status
Status code (defaults to ICanBoogie\Routing\Status::FOUND, 302).
$headers
Additional headers.
Returns
ICanBoogie\HTTP\RedirectResponse
protected
forward_to_route ( ICanBoogie\Routing\Route
$route
)
: ICanBoogie\HTTP\Response|mixed
Forwards dispatching to another router.
Forwards dispatching to another router.
Parameters
Returns
ICanBoogie\HTTP\Response|mixed
Properties summary
Magic properties
public
$response
: ICanBoogie\HTTP\Response
public read-only
$name
: string
The name of the controller.
public read-only
$request
: ICanBoogie\HTTP\Request
The request being dispatched.