- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 5.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\RemoteNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Set the Endpoint closure
editSet the Endpoint closure
editThe client uses an Endpoint closure to dispatch API requests to the correct Endpoint object. A namespace object will construct a new Endpoint via this closure, which means this is a handy location if you wish to extend the available set of API endpoints available
For example, we could add a new endpoint like so:
$transport = $this->transport; $serializer = $this->serializer; $newEndpoint = function ($class) use ($transport, $serializer) { if ($class == 'SuperSearch') { return new MyProject\SuperSearch($transport); } else { // Default handler $fullPath = '\\Elasticsearch\\Endpoints\\' . $class; if ($class === 'Bulk' || $class === 'Msearch' || $class === 'MPercolate') { return new $fullPath($transport, $serializer); } else { return new $fullPath($transport); } } }; $client = ClientBuilder::create() ->setEndpoint($newEndpoint) ->build();
Obviously, by doing this you take responsibility that all existing endpoints still function correctly. And you also assume the responsibility of correctly wiring the Transport and Serializer into each endpoint.
Was this helpful?
Thank you for your feedback.