Class DocumentContext
Provides a context provider for Elasticsearch documents.
Constants
- 
          
          
array<string>VALID_ATTRIBUTES ¶['length', 'precision', 'comment', 'null', 'default'] 
Property Summary
- 
        $_context protected
arrayThe context data
 - 
        $_isCollection protected
boolBoolean to track whether or not the entity is a collection.
 - 
        $_request protected
Cake\Http\ServerRequestThe request object.
 - 
        $_rootName protected
stringThe name of the top level entity/index object.
 
Method Summary
- 
          
__construct() public
Constructor.
 - 
          
_prepare() protected
Prepare some additional data from the context.
 - 
          
attributes() public
Get an associative array of other attributes for a field name.
 - 
          
entity() protected
Get the entity that is closest to $path.
 - 
          
error() public
Get the errors for a given field
 - 
          
fieldNames() public
Get the field names of the top level object in this context.
 - 
          
getMaxLength() public
Get field length from validation
 - 
          
getPrimaryKey() public
Get the fields used in the context as a primary key.
 - 
          
getProp() protected
Read property values or traverse arrays/iterators.
 - 
          
getRequiredMessage() public
Gets the default "required" error message for a field
 - 
          
getValidator() protected
Get the validator for the current index.
 - 
          
hasError() public
Check whether a field has an error attached to it
 - 
          
isCreate() public
Returns whether this form is for a create operation.
 - 
          
isPrimaryKey() public
Returns true if the passed field name is part of the primary key for this context
 - 
          
isRequired() public
Check if a given field is 'required'.
 - 
          
type() public
Get the abstract field type for a given field name.
 - 
          
val() public
Get the current value for a given field.
 
Method Detail
__construct() ¶ public
__construct(Cake\Http\ServerRequest $request, array $context)
      Constructor.
Parameters
- 
                
Cake\Http\ServerRequest$request The request object.
- 
                
array$context Context info.
_prepare() ¶ protected
_prepare(): void
      Prepare some additional data from the context.
If the table option was provided to the constructor and it was a string, IndexRegistry will be used to get the correct table instance.
If an object is provided as the index option, it will be used as is.
If no index option is provided, the index name will be derived based on naming conventions. This inference will work with a number of common objects like arrays, Collection objects and ResultSets.
Returns
voidThrows
RuntimeExceptionWhen a table object cannot be located/inferred.
attributes() ¶ public
attributes(string $field): array
      Get an associative array of other attributes for a field name.
Parameters
- 
                
string$field 
Returns
arrayentity() ¶ protected
entity(array $path): Cake\Datasource\EntityInterface|array|false
      Get the entity that is closest to $path.
Parameters
- 
                
array$path The to get an entity for.
Returns
Cake\Datasource\EntityInterface|array|falseThe entity or false.
Throws
RuntimeExceptionwhen no entity can be found.
error() ¶ public
error(string $field): array
      Get the errors for a given field
Parameters
- 
                
string$field 
Returns
arrayfieldNames() ¶ public
fieldNames(): array<string>
      Get the field names of the top level object in this context.
Returns
array<string>getMaxLength() ¶ public
getMaxLength(string $field): int|null
      Get field length from validation
Parameters
- 
                
string$field The dot separated path to the field you want to check.
Returns
int|nullgetPrimaryKey() ¶ public
getPrimaryKey(): array<string>
      Get the fields used in the context as a primary key.
Returns
array<string>getProp() ¶ protected
getProp(mixed $target, string $field): mixed
      Read property values or traverse arrays/iterators.
Parameters
- 
                
mixed$target The entity/array/collection to fetch $field from.
- 
                
string$field The next field to fetch.
Returns
mixedgetRequiredMessage() ¶ public
getRequiredMessage(string $field): string|null
      Gets the default "required" error message for a field
Parameters
- 
                
string$field 
Returns
string|nullgetValidator() ¶ protected
getValidator(): Cake\Validation\Validator
      Get the validator for the current index.
Returns
Cake\Validation\ValidatorThe validator for the index.
hasError() ¶ public
hasError(string $field): bool
      Check whether a field has an error attached to it
Parameters
- 
                
string$field 
Returns
boolisCreate() ¶ public
isCreate(): bool
      Returns whether this form is for a create operation.
Returns
boolisPrimaryKey() ¶ public
isPrimaryKey(string $field): bool
      Returns true if the passed field name is part of the primary key for this context
Parameters
- 
                
string$field 
Returns
boolisRequired() ¶ public
isRequired(string $field): bool
      Check if a given field is 'required'.
In this context class, this is simply defined by the 'required' array.
Parameters
- 
                
string$field 
Returns
booltype() ¶ public
type(string $field): string|null
      Get the abstract field type for a given field name.
Parameters
- 
                
string$field 
Returns
string|nullval() ¶ public
val(string $field, array<string, mixed> $options = []): mixed
      Get the current value for a given field.
Classes implementing this method can optionally have a second argument
$options. Valid key for $options array are:
default: Default value to return if no value found in data or context record.schemaDefault: Boolean indicating whether default value from context's schema should be used if it's not explicitly provided.
Parameters
- 
                
string$field - 
                
array<string, mixed>$options optional 
Returns
mixed