3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Factory for search endpoints. */ class SearchEndpointFactory { /** * @var array Holds namespaces for endpoints. */ private static $endpoints = [ 'query' => 'ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint', 'post_filter' => 'ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint', 'sort' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint', 'highlight' => 'ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint', 'aggregations' => 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint', 'suggest' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint', 'inner_hits' => 'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint', ]; /** * Returns a search endpoint instance. * * @param string $type Type of endpoint. * * @return SearchEndpointInterface * * @throws \RuntimeException Endpoint does not exist. */ public static function get($type) { if (!array_key_exists($type, self::$endpoints)) { throw new \RuntimeException('Endpoint does not exist.'); } var_dump((self::$endpoints[$type])); die; return new (self::$endpoints[$type])(); } } var_dump(SearchEndpointFactory::get('query'));

preferences:
41.5 ms | 712 KiB | 5 Q