CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
      • Attribute
      • Component
      • Exception
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ControllerFactory

Factory method for building controllers for request.

Namespace: Cake\Controller

Property Summary

  • $controller protected
    Cake\Controller\Controller

Method Summary

  • __construct() public

    Constructor

  • applyArgsByNameMap() protected

    Applies named argument mapping to positional route parameters.

  • canAutoWire() protected

    Check whether a type can be auto-wired by the container.

  • coerceStringToType() protected

    Coerces string argument to primitive type.

  • create() public

    Create a controller for a given request.

  • getActionArgs() protected

    Get the arguments for the controller action invocation.

  • getControllerClass() public

    Determine the controller class name based on current request and controller param

  • getFirstPositionalParamKey() protected

    Returns the first positional argument key from route params.

  • handle() public

    Invoke the action.

  • invoke() public

    Invoke a controller's action and wrapping methods.

  • missingController() protected

    Throws an exception when a controller is missing.

  • resolveParameterAttribute() protected

    Resolve parameter value from attributes implementing ParameterAttributeInterface.

Method Detail

__construct() ¶ public

__construct(Cake\Container\ContainerInterface $container)

Constructor

Parameters
Cake\Container\ContainerInterface $container

The container to build controllers with.

applyArgsByNameMap() ¶ protected

applyArgsByNameMap(array<int, mixed> $passedParams, array<string, int> $argsByName): array<int|string, mixed>

Applies named argument mapping to positional route parameters.

Parameters
array<int, mixed> $passedParams

Positional route parameters.

array<string, int> $argsByName

Parameter-name to index map.

Returns
array<int|string, mixed>

canAutoWire() ¶ protected

canAutoWire(string $typeName): bool

Check whether a type can be auto-wired by the container.

Parameters
string $typeName

The type name to check.

Returns
bool

coerceStringToType() ¶ protected

coerceStringToType(string $argument, ReflectionNamedType $type): array|string|float|int|bool|null

Coerces string argument to primitive type.

Parameters
string $argument

Argument to coerce

ReflectionNamedType $type

Parameter type

Returns
array|string|float|int|bool|null

create() ¶ public

create(Psr\Http\Message\ServerRequestInterface $request): Cake\Controller\Controller

Create a controller for a given request.

Parameters
Psr\Http\Message\ServerRequestInterface $request

The request to build a controller for.

Returns
Cake\Controller\Controller
Throws
Cake\Http\Exception\MissingControllerException

getActionArgs() ¶ protected

getActionArgs(Closure $action, array<int|string, mixed> $passedParams, array<string, int> $argsByName = []): array<int, mixed>

Get the arguments for the controller action invocation.

Parameters
Closure $action

Controller action.

array<int|string, mixed> $passedParams

Params passed by the router.

array<string, int> $argsByName optional

Parameter-name to positional-index map.

Returns
array<int, mixed>

getControllerClass() ¶ public

getControllerClass(Cake\Http\ServerRequest $request): class-string<Cake\Controller\Controller>|null

Determine the controller class name based on current request and controller param

Parameters
Cake\Http\ServerRequest $request

The request to build a controller for.

Returns
class-string<Cake\Controller\Controller>|null

getFirstPositionalParamKey() ¶ protected

getFirstPositionalParamKey(array<int|string, mixed> $passedParams): int|null

Returns the first positional argument key from route params.

Parameters
array<int|string, mixed> $passedParams

Passed route parameters.

Returns
int|null

handle() ¶ public

handle(ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

Invoke the action.

Parameters
ServerRequestInterface $request

Request instance.

Returns
Psr\Http\Message\ResponseInterface

invoke() ¶ public

invoke(TController $controller): Psr\Http\Message\ResponseInterface

Invoke a controller's action and wrapping methods.

Parameters
TController $controller

The controller to invoke.

Returns
Psr\Http\Message\ResponseInterface

The response

Throws
Cake\Controller\Exception\MissingActionException
If controller action is not found.
UnexpectedValueException
If return value of action method is not null or ResponseInterface instance.

missingController() ¶ protected

missingController(Cake\Http\ServerRequest $request): Cake\Http\Exception\MissingControllerException

Throws an exception when a controller is missing.

Parameters
Cake\Http\ServerRequest $request

The request.

Returns
Cake\Http\Exception\MissingControllerException

resolveParameterAttribute() ¶ protected

resolveParameterAttribute(ReflectionParameter $parameter, Cake\Http\ServerRequest $request): mixed

Resolve parameter value from attributes implementing ParameterAttributeInterface.

Parameters
ReflectionParameter $parameter

The parameter to resolve

Cake\Http\ServerRequest $request

The server request

Returns
mixed

The resolved value or null if no matching attribute found

Property Detail

$controller ¶ protected

Type
Cake\Controller\Controller
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs