\Cake\View\FormContextFactory

Factory for getting form context instance based on provided data.

Summary

Methods
Properties
Constants
__construct()
createWithDefaults()
addProvider()
get()
No public properties found
No constants found
No protected methods found
$providers
N/A
No private methods found
No private properties found
N/A

Properties

$providers

$providers : array

Context providers.

Type

array

Methods

__construct()

__construct(array  $providers = array()) 

Constructor.

Parameters

array $providers

Array of provider callables. Each element should be of form ['type' => 'a-string', 'callable' => ..]

createWithDefaults()

createWithDefaults(array  $providers = array()) : \Cake\View\Form\ContextFactory

Create factory instance with providers "array", "form" and "orm".

Parameters

array $providers

Array of provider callables. Each element should be of form ['type' => 'a-string', 'callable' => ..]

Returns

\Cake\View\Form\ContextFactory

addProvider()

addProvider(string  $type, callable  $check) : $this

Add a new context type.

Form context types allow FormHelper to interact with data providers that come from outside CakePHP. For example if you wanted to use an alternative ORM like Doctrine you could create and connect a new context class to allow FormHelper to read metadata from doctrine.

Parameters

string $type

The type of context. This key can be used to overwrite existing providers.

callable $check

A callable that returns an object when the form context is the correct type.

Returns

$this

get()

get(\Cake\Http\ServerRequest  $request, array  $data = array()) : \Cake\View\Form\ContextInterface

Find the matching context for the data.

If no type can be matched a NullContext will be returned.

Parameters

\Cake\Http\ServerRequest $request

Request instance.

array $data

The data to get a context provider for.

Throws

\RuntimeException

when the context class does not implement the ContextInterface.

Returns

\Cake\View\Form\ContextInterface

Context provider.