Skip to content

Instantly share code, notes, and snippets.

@atakde
Created January 6, 2024 09:52
Show Gist options
  • Save atakde/4c640a0fd2368055af950076cf0eb64e to your computer and use it in GitHub Desktop.
Save atakde/4c640a0fd2368055af950076cf0eb64e to your computer and use it in GitHub Desktop.
Elastic PHP (Medium Ex)
<?php
namespace Atakan\ElasticEx;
class Elastic
{
private static $instance = null;
private $client = null;
private function __construct()
{
$this->client = \Elastic\Elasticsearch\ClientBuilder::create()
->setHosts([$_ENV['ELASTIC_HOST']])
->setApiKey($_ENV['ELASTIC_API_KEY'])
->build();
}
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new Elastic();
}
return self::$instance;
}
public function getClient()
{
return $this->client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment