Cake\ElasticSearch\View\Form\DocumentContext::_prepare PHP Метод

_prepare() защищенный Метод

If the table option was provided to the constructor and it was a string, TypeRegistry will be used to get the correct table instance. If an object is provided as the type option, it will be used as is. If no type option is provided, the type name will be derived based on naming conventions. This inference will work with a number of common objects like arrays, Collection objects and ResultSets.
protected _prepare ( ) : void
Результат void
    protected function _prepare()
    {
        $type = $this->_context['type'];
        $entity = $this->_context['entity'];
        if (empty($type)) {
            if (is_array($entity) || $entity instanceof Traversable) {
                $entity = (new Collection($entity))->first();
            }
            $isDocument = $entity instanceof Document;
            if ($isDocument) {
                $type = $entity->source();
            }
            if (!$type && $isDocument && get_class($entity) !== 'Cake\\ElasticSearch\\Document') {
                list(, $entityClass) = namespaceSplit(get_class($entity));
                $type = Inflector::pluralize($entityClass);
            }
        }
        if (is_string($type)) {
            $type = TypeRegistry::get($type);
        }
        if (!is_object($type)) {
            throw new RuntimeException('Unable to find type class for current entity');
        }
        $this->_isCollection = is_array($entity) || $entity instanceof Traversable;
        $this->_rootName = $type->name();
        $this->_context['type'] = $type;
    }