So I'm using more specifically Elasticsearch which is available through composer. It is the 5.0 version. I'm trying to build the client connection inside a private function inside a class. Basically what I want is 1 class with 2 private functions. The first private function will create the client connection using:
$hosts = ['host' => 'http://censored'];
$clientBuilder = ClientBuilder::create();
$clientBuilder->setHosts($hosts);
$clientBuilder->setSerializer('\Elasticsearch\Serializers\EverythingToJSONSerializer');
$client = $clientBuilder->build();
$searchParams = ['index' => 'main'];
Mind you that $searchparams and $client will have to be accessible by the second private function mentioned below.
The second private function will take in a type and query from the public function and use $client and $searchparam to initiate a API request to Elasticsearch
Summary: The public function will be called from another file. To use it it will require a type ($type) and query ($query) to be passed, which will be passed to the second private function. The second private function will initiate a API request to Elasticsearch and give back the results to the public function, which then the public function will echo out the results back to the user.
I believe this is possible, but I don't know how to call or use another namespace within a private function. Putting that into a private function and autoloading Elasticsearch beforehand results in ClientBuilder not being found.
Thank you in advance and sorry for the long post.