Created
January 6, 2024 09:52
-
-
Save atakde/4c640a0fd2368055af950076cf0eb64e to your computer and use it in GitHub Desktop.
Elastic PHP (Medium Ex)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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