<?php


namespace Api\PhpUtils\Elastic;

use Api\PhpUtils\Elastic\Manager\DocumentManager;
use Api\PhpUtils\Elastic\Manager\IndexManager;
use Elasticsearch\ClientBuilder;

final class ElasticUtil
{
    use IndexManager, DocumentManager;

    /**
     * @var ElasticUtil
     */
    private static $instance;

    /**
     * ElasticUtil constructor.
     */
    public function __construct()
    {
        $hosts = ['http://localhost:9200'];  //todo 读取yaconf

        $this->client = ClientBuilder::create()->setHosts($hosts)->build();
    }

    /**
     * @return ElasticUtil
     */
    public static function getInstance(): ElasticUtil
    {
        if (empty(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}