| @@ 13-50 (lines=38) @@ | ||
| 10 | * |
|
| 11 | * @author gbprod <[email protected]> |
|
| 12 | */ |
|
| 13 | class CreateIndexHandler |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var IndexConfigurationRepository |
|
| 17 | */ |
|
| 18 | private $configurationRepository; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @param IndexConfigurationRepository $configurationRepository |
|
| 22 | */ |
|
| 23 | public function __construct(IndexConfigurationRepository $configurationRepository) |
|
| 24 | { |
|
| 25 | $this->configurationRepository = $configurationRepository; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Handle index creation command |
|
| 30 | * |
|
| 31 | * @param Client $client |
|
| 32 | * @param string $index |
|
| 33 | */ |
|
| 34 | public function handle(Client $client, $index) |
|
| 35 | { |
|
| 36 | $config = $this->configurationRepository->get($index); |
|
| 37 | ||
| 38 | if (null === $config) { |
|
| 39 | throw new \InvalidArgumentException(); |
|
| 40 | } |
|
| 41 | ||
| 42 | $client |
|
| 43 | ->indices() |
|
| 44 | ->create([ |
|
| 45 | 'index' => $index, |
|
| 46 | 'body' => $config, |
|
| 47 | ]) |
|
| 48 | ; |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 13-49 (lines=37) @@ | ||
| 10 | * |
|
| 11 | * @author gbprod <[email protected]> |
|
| 12 | */ |
|
| 13 | class DeleteIndexHandler |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var IndexConfigurationRepository |
|
| 17 | */ |
|
| 18 | private $configurationRepository; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @param IndexConfigurationRepository $configurationRepository |
|
| 22 | */ |
|
| 23 | public function __construct(IndexConfigurationRepository $configurationRepository) |
|
| 24 | { |
|
| 25 | $this->configurationRepository = $configurationRepository; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Handle index deletion command |
|
| 30 | * |
|
| 31 | * @param Client $client |
|
| 32 | * @param string $index |
|
| 33 | */ |
|
| 34 | public function handle(Client $client, $index) |
|
| 35 | { |
|
| 36 | $config = $this->configurationRepository->get($index); |
|
| 37 | ||
| 38 | if (null === $config) { |
|
| 39 | throw new \InvalidArgumentException(); |
|
| 40 | } |
|
| 41 | ||
| 42 | $client |
|
| 43 | ->indices() |
|
| 44 | ->delete([ |
|
| 45 | 'index' => $index, |
|
| 46 | ]) |
|
| 47 | ; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||