PHP Класс Cake\ElasticSearch\Type

A type in elastic search is approximately equivalent to a table or collection in a relational datastore. While an index can have multiple types, this ODM maps each type in an index maps to a class.
Наследование: implements Cake\Datasource\RepositoryInterface, implements Cake\Event\EventDispatcherInterface, use trait Cake\Event\EventManagerTrait, use trait Cake\Datasource\RulesAwareTrait, use trait Cake\Validation\ValidatorAwareTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_connection Cake\ElasticSearch\Datasource\Connection Connection instance
$_documentClass string The name of the class that represent a single document for this type
$_name string The name of the Elastic Search type this class represents
$embeds array Collection of Embedded sub documents this type has.
$schema Cake\ElasticSearch\Datasource\MappingSchema The mapping schema for this type.

Открытые методы

Метод Описание
__construct ( array $config = [] ) Constructor
alias ( string $alias = null ) : string Get the alias for this Type.
callFinder ( string $type, Query $query, array $options = [] ) : Query Calls a finder method directly and applies it to the passed query, if no query is passed a new one will be created and returned
connection ( Connection $conn = null ) : Connection Returns the connection instance or sets a new one
defaultConnectionName ( ) : string The default connection name to inject when creating an instance.
delete ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean Delete a single entity.
deleteAll ( array $conditions ) : boolean Delete all matching records.
embedMany ( string $name, array $options = [] ) : void Mark a property in documents of this type as list of embedded sub-documents.
embedOne ( string $name, array $options = [] ) : void Mark a property in documents of this type as an embedded sub-document.
embedded ( ) : array Get the list of embedded documents this type has.
entityClass ( string $name = null ) : string Returns the class used to hydrate rows for this table or sets a new one
exists ( array $conditions ) : boolean Returns true if there is any record in this repository matching the specified conditions.
find ( string $type = 'all', array $options = [] ) : Query Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
findAll ( Query $query, array $options = [] ) : Query Returns the query as passed
get ( string $primaryKey, array $options = [] ) : Document
getEventManager ( ) : Cake\Event\EventManager Get the event manager for this Table.
hasField ( string $field ) : boolean Check whether or not a field exists in the mapping.
implementedEvents ( ) : array Get the callbacks this Type is interested in.
initialize ( array $config ) : void Initialize a table instance. Called after the constructor.
marshaller ( ) : Marshaller Get a marshaller for this Type instance.
name ( string $name = null ) : string Returns the type name name or sets a new one
newEntities ( array $data, array $options = [] ) : array Create a list of entities + associated entities from an array.
newEntity ( array | null $data = null, array $options = [] ) : Cake\Datasource\EntityInterface Create a new entity + associated entities from an array.
patchEntities ( array | Traversable $entities, array $data, array $options = [] ) : array Merges each of the elements passed in $data into the entities found in $entities respecting the accessible fields configured on the entities.
patchEntity ( Cake\Datasource\EntityInterface $entity, array $data, array $options = [] ) : Cake\Datasource\EntityInterface Merges the passed $data into $entity respecting the accessible fields configured on the entity. Returns the same entity after being altered.
query ( ) : Query Creates a new Query instance for this repository
save ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : Cake\Datasource\EntityInterface | boolean Persists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.
schema ( ) : array Get the mapping data from the index type.
table ( string $table = null ) : string Get/set the type/table name for this type.
updateAll ( array $fields, array $conditions ) : void Update all matching records.

Описание методов

__construct() публичный Метод

### Options - connection The Elastica instance. - name The name of the type. If this isn't set the name will be inferred from the class name. - eventManager Used to inject a specific eventmanager. At the end of the constructor the Model.initialize event will be triggered.
public __construct ( array $config = [] )
$config array The configuration options, see above.

alias() публичный Метод

This method is just an alias of name().
public alias ( string $alias = null ) : string
$alias string The new type name
Результат string

callFinder() публичный Метод

Calls a finder method directly and applies it to the passed query, if no query is passed a new one will be created and returned
public callFinder ( string $type, Query $query, array $options = [] ) : Query
$type string name of the finder to be called
$query Query The query object to apply the finder options to
$options array List of options to pass to the finder
Результат Query

connection() публичный Метод

Returns the connection instance or sets a new one
public connection ( Connection $conn = null ) : Connection
$conn Cake\ElasticSearch\Datasource\Connection the new connection instance
Результат Cake\ElasticSearch\Datasource\Connection

defaultConnectionName() публичный статический Метод

The default connection name to inject when creating an instance.
public static defaultConnectionName ( ) : string
Результат string

delete() публичный Метод

Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association. Triggers the Model.beforeDelete and Model.afterDelete events.
public delete ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean
$entity Cake\Datasource\EntityInterface The entity to remove.
$options array The options for the delete.
Результат boolean success

deleteAll() публичный Метод

Deletes all records matching the provided conditions. This method will *not* trigger beforeDelete/afterDelete events. If you need those first load a collection of records and delete them.
См. также: RepositoryInterface::delete()
public deleteAll ( array $conditions ) : boolean
$conditions array An array of conditions, similar to those used with find()
Результат boolean Success Returns true if one or more rows are effected.

embedMany() публичный Метод

Embedded documents are converted into instances of the named document type. This allows you to attach entity level behavior to subsections of your documents. This method will make a list of embedded documents from the named property.
public embedMany ( string $name, array $options = [] ) : void
$name string The name of the property that contains the embedded document.
$options array The options for the embedded document.
Результат void

embedOne() публичный Метод

Embedded documents are converted into instances of the named document type. This allows you to attach entity level behavior to subsections of your documents.
public embedOne ( string $name, array $options = [] ) : void
$name string The name of the property that contains the embedded document.
$options array The options for the embedded document.
Результат void

embedded() публичный Метод

Get the list of embedded documents this type has.
public embedded ( ) : array
Результат array

entityClass() публичный Метод

Returns the class used to hydrate rows for this table or sets a new one
public entityClass ( string $name = null ) : string
$name string the name of the class to use
Результат string

exists() публичный Метод

Returns true if there is any record in this repository matching the specified conditions.
public exists ( array $conditions ) : boolean
$conditions array list of conditions to pass to the query
Результат boolean

find() публичный Метод

### Model.beforeFind event Each find() will trigger a Model.beforeFind event for all attached listeners. Any listener can set a valid result set using $query
public find ( string $type = 'all', array $options = [] ) : Query
$type string the type of query to perform
$options array An array that will be passed to Query::applyOptions
Результат Query

findAll() публичный Метод

Returns the query as passed
public findAll ( Query $query, array $options = [] ) : Query
$query Query An Elasticsearch query object
$options array An array of options to be used for query logic
Результат Query

get() публичный Метод

public get ( string $primaryKey, array $options = [] ) : Document
$primaryKey string The document's primary key
$options array An array of options
Результат Document A new Elasticsearch document entity

getEventManager() публичный Метод

Get the event manager for this Table.
public getEventManager ( ) : Cake\Event\EventManager
Результат Cake\Event\EventManager

hasField() публичный Метод

Check whether or not a field exists in the mapping.
public hasField ( string $field ) : boolean
$field string The field to check.
Результат boolean

implementedEvents() публичный Метод

By implementing the conventional methods a Type class is assumed to be interested in the related event. Override this method if you need to add non-conventional event listeners. Or if you want you table to listen to non-standard events. The conventional method map is: - Model.beforeMarshal => beforeMarshal - Model.beforeFind => beforeFind - Model.beforeSave => beforeSave - Model.afterSave => afterSave - Model.beforeDelete => beforeDelete - Model.afterDelete => afterDelete - Model.beforeRules => beforeRules - Model.afterRules => afterRules
public implementedEvents ( ) : array
Результат array

initialize() публичный Метод

You can use this method to define embedded documents, define validation and do any other initialization logic you need. public function initialize(array $config) { $this->embedMany('Comments'); }
public initialize ( array $config ) : void
$config array Configuration options passed to the constructor
Результат void

marshaller() публичный Метод

Get a marshaller for this Type instance.
public marshaller ( ) : Marshaller
Результат Marshaller

name() публичный Метод

Returns the type name name or sets a new one
public name ( string $name = null ) : string
$name string the new type name
Результат string

newEntities() публичный Метод

This is most useful when hydrating request data back into entities. For example, in your controller code: $articles = $this->Articles->newEntities($this->request->data()); The hydrated entities can then be iterated and saved.
public newEntities ( array $data, array $options = [] ) : array
$data array The data to build an entity with.
$options array A list of options for the objects hydration.
Результат array An array of hydrated records.

newEntity() публичный Метод

This is most useful when hydrating request data back into entities. For example, in your controller code: $article = $this->Articles->newEntity($this->request->data()); The hydrated entity will correctly do an insert/update based on the primary key data existing in the database when the entity is saved. Until the entity is saved, it will be a detached record.
public newEntity ( array | null $data = null, array $options = [] ) : Cake\Datasource\EntityInterface
$data array | null The data to build an entity with.
$options array A list of options for the object hydration.
Результат Cake\Datasource\EntityInterface

patchEntities() публичный Метод

Merging is done by matching the primary key in each of the elements in $data and $entities. This is most useful when editing a list of existing entities using request data: $article = $this->Articles->patchEntities($articles, $this->request->data());
public patchEntities ( array | Traversable $entities, array $data, array $options = [] ) : array
$entities array | Traversable the entities that will get the data merged in
$data array list of arrays to be merged into the entities
$options array A list of options for the objects hydration.
Результат array

patchEntity() публичный Метод

This is most useful when editing an existing entity using request data: $article = $this->Articles->patchEntity($article, $this->request->data());
public patchEntity ( Cake\Datasource\EntityInterface $entity, array $data, array $options = [] ) : Cake\Datasource\EntityInterface
$entity Cake\Datasource\EntityInterface the entity that will get the data merged in
$data array key value list of fields to be merged into the entity
$options array A list of options for the object hydration.
Результат Cake\Datasource\EntityInterface

query() публичный Метод

Creates a new Query instance for this repository
public query ( ) : Query
Результат Query

save() публичный Метод

Triggers the Model.beforeSave and Model.afterSave events. ## Options - checkRules Defaults to true. Check deletion rules before deleting the record.
public save ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : Cake\Datasource\EntityInterface | boolean
$entity Cake\Datasource\EntityInterface The entity to be saved
$options array An array of options to be used for the event
Результат Cake\Datasource\EntityInterface | boolean

schema() публичный Метод

This will fetch the schema from ElasticSearch the first time this method is called.
public schema ( ) : array
Результат array

table() публичный Метод

Get/set the type/table name for this type.
public table ( string $table = null ) : string
$table string The 'table' name for this type.
Результат string

updateAll() публичный Метод

Sets the $fields to the provided values based on $conditions. This method will *not* trigger beforeSave/afterSave events. If you need those first load a collection of records and update them.
public updateAll ( array $fields, array $conditions ) : void
$fields array A hash of field => new value.
$conditions array An array of conditions, similar to those used with find()
Результат void

Описание свойств

$_connection защищенное свойство

Connection instance
protected Connection,Cake\ElasticSearch\Datasource $_connection
Результат Cake\ElasticSearch\Datasource\Connection

$_documentClass защищенное свойство

The name of the class that represent a single document for this type
protected string $_documentClass
Результат string

$_name защищенное свойство

The name of the Elastic Search type this class represents
protected string $_name
Результат string

$embeds защищенное свойство

Collection of Embedded sub documents this type has.
protected array $embeds
Результат array

$schema защищенное свойство

The mapping schema for this type.
protected MappingSchema,Cake\ElasticSearch\Datasource $schema
Результат Cake\ElasticSearch\Datasource\MappingSchema