Completed
Pull Request — develop (#39)
by Sam
01:56
created

CreateCommand::getElasticsearchService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Console;
2
3
class CreateCommand extends AbstractCommand
4
{
5
6
    /**
7
     * The name and signature of the console command.
8
     *
9
     * @var string
10
     */
11
    protected $signature = 'elastic:index:create {config : Configuration file}';
12
13
    /**
14
     * The console command description.
15
     *
16
     * @var string
17
     */
18
    protected $description = 'Creates an Elasticsearch index from a configuration file.';
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function handle()
24
    {
25
        $config = (string)$this->argument('config');
26
27
        $filePath = realpath($config);
28
29
        if (!file_exists($filePath)) {
30
            $this->error(sprintf("Configuration file '%s' does not exist.", $config));
31
32
            return 1;
33
        }
34
35
        $params = require($filePath);
36
37
        $this->info('Creating index ...');
38
39
        $this->elasticsearchService->indices()->create($params);
40
41
        $this->info(sprintf("Index '%s' created.", $params['index']));
42
43
        return 0;
44
    }
45
}
46