src/Model.php
/**
     * A custom factory method that will try to detect the correct model class 
     * and instantiate and object of it.
     * 
     * @param array $esHit
     * @param string $className a class name or pattern.
     * @param Client $esClient ElasticSearch client
     * @return Model
     */
A custom factory method that will try to detect the correct model class
and instantiate and object of it.

@param array $esHit
@param string $className a class name or pattern.
@param Client $esClient ElasticSearch client
@return Model
A custom factory method that will try to detect the correct model class and instantiate and object of it . @param array $esHit @param string $className a class name or pattern . @param Client $esClient ElasticSearch client @return Model
public static function MakeOfType(array $esHit, $className = "", Client $esClient = null) {
        if ($className && strpos($className, '{type}') !== false) {
            $baseClassName = str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9]+/', ' ', $esHit['_type'])));
            $fullClassName = str_replace("{type}", $baseClassName, $className);
            if (!class_exists($fullClassName)) {
                $fullClassName = array_key_exists('_source', $esHit) ? static::class : ArrayObject::class;
            }
        } else {
            $fullClassName = $className? : static::class;
        }
        return $fullClassName::make($esHit, $esClient);
    }
public static function MakeOfType ( array $ esHit , $ className = " " , Client $ esClient = null ) { if ( $ className && strpos ( $ className , '{type}' ) !== false ) { $ baseClassName = str_replace ( ' ' , '' , ucwords ( preg_replace ( '/[^a-zA-Z0-9]+/' , ' ' , $ esHit [ '_type' ] ) ) ) ; $ fullClassName = str_replace ( " {type} " , $ baseClassName , $ className ) ; if ( ! class_exists ( $ fullClassName ) ) { $ fullClassName = array_key_exists ( '_source' , $ esHit ) ? static :: class : ArrayObject :: class ; } } else { $ fullClassName = $ className ? : static :: class ; } return $ fullClassName :: make ( $ esHit , $ esClient ) ; }
A custom factory method that will try to detect the correct model class
 and instantiate and object of it.
A custom factory method that will try to detect the correct model class and instantiate and object of it .