Cake\ElasticSearch\Document::__construct PHP Method

__construct() public method

Takes either an array or a Result object form a search and constructs a document representing an entity in a elastic search type,
public __construct ( array | Result $data = [], array $options = [] )
$data array | Elastica\Result An array or Result object that represents an Elasticsearch document
$options array An array of options to set the state of the document
    public function __construct($data = [], $options = [])
    {
        if ($data instanceof Result) {
            $options['result'] = $data;
            $id = $data->getId();
            $data = $data->getData();
            if ($id !== []) {
                $data['id'] = $id;
            }
        }
        $options += ['useSetters' => true, 'markClean' => false, 'markNew' => null, 'guard' => false, 'source' => null, 'result' => null];
        if (!empty($options['source'])) {
            $this->source($options['source']);
        }
        if ($options['markNew'] !== null) {
            $this->isNew($options['markNew']);
        }
        if ($options['result'] !== null) {
            $this->_result = $options['result'];
        }
        if (!empty($data) && $options['markClean'] && !$options['useSetters']) {
            $this->_properties = $data;
            return;
        }
        if (!empty($data)) {
            $this->set($data, ['setter' => $options['useSetters'], 'guard' => $options['guard']]);
        }
        if ($options['markClean']) {
            $this->clean();
        }
    }