ControllerFactory
in package
implements
ControllerFactoryInterface, RequestHandlerInterface
Factory method for building controllers for request.
Tags
Table of Contents
Interfaces
- ControllerFactoryInterface
- Factory method for building controllers from request/response pairs.
- RequestHandlerInterface
- Handles a server request and produces a response.
Properties
Methods
- __construct() : mixed
- Constructor
- create() : Controller
- Create a controller for a given request.
- getControllerClass() : string|null
- Determine the controller class name based on current request and controller param
- handle() : ResponseInterface
- Invoke the action.
- invoke() : ResponseInterface
- Invoke a controller's action and wrapping methods.
- coerceStringToType() : array<string|int, mixed>|string|float|int|bool|null
- Coerces string argument to primitive type.
- getActionArgs() : array<string|int, mixed>
- Get the arguments for the controller action invocation.
- missingController() : MissingControllerException
- Throws an exception when a controller is missing.
Properties
$container
protected
ContainerInterface
$container
$controller
protected
Controller
$controller
Methods
__construct()
Constructor
public
__construct(ContainerInterface $container) : mixed
Parameters
- $container : ContainerInterface
-
The container to build controllers with.
create()
Create a controller for a given request.
public
create(ServerRequestInterface $request) : Controller
Parameters
- $request : ServerRequestInterface
-
The request to build a controller for.
Tags
Return values
ControllergetControllerClass()
Determine the controller class name based on current request and controller param
public
getControllerClass(ServerRequest $request) : string|null
Parameters
- $request : ServerRequest
-
The request to build a controller for.
Tags
Return values
string|nullhandle()
Invoke the action.
public
handle(ServerRequestInterface $request) : ResponseInterface
Parameters
- $request : ServerRequestInterface
-
Request instance.
Return values
ResponseInterfaceinvoke()
Invoke a controller's action and wrapping methods.
public
invoke(Controller $controller) : ResponseInterface
Parameters
- $controller : Controller
-
The controller to invoke.
Tags
Return values
ResponseInterface —The response
coerceStringToType()
Coerces string argument to primitive type.
protected
coerceStringToType(string $argument, ReflectionNamedType $type) : array<string|int, mixed>|string|float|int|bool|null
Parameters
- $argument : string
-
Argument to coerce
- $type : ReflectionNamedType
-
Parameter type
Return values
array<string|int, mixed>|string|float|int|bool|nullgetActionArgs()
Get the arguments for the controller action invocation.
protected
getActionArgs(Closure $action, array<string|int, mixed> $passedParams) : array<string|int, mixed>
Parameters
- $action : Closure
-
Controller action.
- $passedParams : array<string|int, mixed>
-
Params passed by the router.
Return values
array<string|int, mixed>missingController()
Throws an exception when a controller is missing.
protected
missingController(ServerRequest $request) : MissingControllerException
Parameters
- $request : ServerRequest
-
The request.