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