| @@ 13-47 (lines=35) @@ | ||
| 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 | ->getIndex($index) |
|
| 44 | ->create($config) |
|
| 45 | ; |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 13-48 (lines=36) @@ | ||
| 10 | * |
|
| 11 | * @author gbprod <[email protected]> |
|
| 12 | */ |
|
| 13 | class PutIndexMappingsHandler |
|
| 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, $type) |
|
| 35 | { |
|
| 36 | $mapping = $this->configurationRepository->getMapping($index, $type); |
|
| 37 | ||
| 38 | if (!$mapping) { |
|
| 39 | throw new \InvalidArgumentException(); |
|
| 40 | } |
|
| 41 | ||
| 42 | $client |
|
| 43 | ->getIndex($index) |
|
| 44 | ->getType($type) |
|
| 45 | ->setMapping($mapping) |
|
| 46 | ; |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| @@ 14-52 (lines=39) @@ | ||
| 11 | * |
|
| 12 | * @author gbprod <[email protected]> |
|
| 13 | */ |
|
| 14 | class PutIndexSettingsHandler |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var IndexConfigurationRepository |
|
| 18 | */ |
|
| 19 | private $configurationRepository; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param IndexConfigurationRepository $configurationRepository |
|
| 23 | */ |
|
| 24 | public function __construct(IndexConfigurationRepository $configurationRepository) |
|
| 25 | { |
|
| 26 | $this->configurationRepository = $configurationRepository; |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Handle index creation command |
|
| 31 | * |
|
| 32 | * @param Client $client |
|
| 33 | * @param string $index |
|
| 34 | */ |
|
| 35 | public function handle(Client $client, $index) |
|
| 36 | { |
|
| 37 | $settings = $this |
|
| 38 | ->configurationRepository |
|
| 39 | ->getSettings($index) |
|
| 40 | ; |
|
| 41 | ||
| 42 | if (null === $settings) { |
|
| 43 | throw new \InvalidArgumentException(); |
|
| 44 | } |
|
| 45 | ||
| 46 | $client |
|
| 47 | ->getIndex($index) |
|
| 48 | ->setSettings($settings) |
|
| 49 | ; |
|
| 50 | } |
|
| 51 | ||
| 52 | } |
|
| 53 | ||