├── LICENSE ├── composer.json └── src └── DI └── ElasticsearchExtension.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Contributte 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contributte/elasticsearch", 3 | "description": "Tiny Elasticsearch integration into Nette Framework", 4 | "keywords": [ 5 | "contributte", 6 | "nette", 7 | "elasticsearch", 8 | "search", 9 | "elastic", 10 | "es" 11 | ], 12 | "type": "library", 13 | "license": "MIT", 14 | "homepage": "https://github.com/contributte/elasticsearch", 15 | "authors": [ 16 | { 17 | "name": "Milan Felix Šulc", 18 | "homepage": "https://f3l1x.io" 19 | } 20 | ], 21 | "require": { 22 | "php": ">=8.1", 23 | "elasticsearch/elasticsearch": "^8.11.0", 24 | "nette/di": "^3.1.8" 25 | }, 26 | "require-dev": { 27 | "contributte/qa": "^0.4", 28 | "contributte/tester": "^0.4", 29 | "contributte/phpstan": "^0.1" 30 | }, 31 | "conflict": { 32 | "psr/http-message": "<2.0" 33 | }, 34 | "autoload": { 35 | "psr-4": { 36 | "Contributte\\Elasticsearch\\": "src/" 37 | } 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "Tests\\Cases\\": "tests/cases" 42 | } 43 | }, 44 | "minimum-stability": "dev", 45 | "prefer-stable": true, 46 | "config": { 47 | "sort-packages": true, 48 | "allow-plugins": { 49 | "dealerdirect/phpcodesniffer-composer-installer": true, 50 | "php-http/discovery": true 51 | } 52 | }, 53 | "extra": { 54 | "branch-alias": { 55 | "dev-master": "0.6.x-dev" 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/DI/ElasticsearchExtension.php: -------------------------------------------------------------------------------- 1 | Expect::arrayOf(Expect::string())->required()->min(1), 22 | 'retries' => Expect::int(1), 23 | 'sslVerification' => Expect::bool(true), 24 | 'apiKey' => Expect::anyOf(Expect::arrayOf(Expect::string())->min(1)->max(2), null), 25 | 'basicAuthentication' => Expect::anyOf(Expect::arrayOf(Expect::string())->min(2)->max(2), null), 26 | ]); 27 | } 28 | 29 | public function beforeCompile(): void 30 | { 31 | $config = $this->getConfig(); 32 | $config = array_filter((array) $config, fn ($value) => $value !== null); 33 | $builder = $this->getContainerBuilder(); 34 | 35 | $builder->addDefinition($this->prefix('client')) 36 | ->setType(Client::class) 37 | ->setFactory([ClientBuilder::class, 'fromConfig']) 38 | ->setArguments([$config]); 39 | } 40 | 41 | } 42 | --------------------------------------------------------------------------------