Completed
Push — master ( 5018c3...5108e7 )
by GBProd
07:07
created

DataProvider::populate()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
namespace GBProd\ElasticsearchDataProviderBundle\DataProvider;
4
5
use Elasticsearch\Client;
6
7
/**
8
 * Abstract class for data providing
9
 *
10
 * @author gbprod <[email protected]>
11
 */
12
abstract class DataProvider
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18
19
    /**
20
     * @var string
21
     */
22
    private $index;
23
24
    /**
25
     * @var string
26
     */
27
    private $type;
28
29
    /**
30
     * Populate index
31
     *
32
     * @param Client $client
33
     * @index string $index
34
     * @index string $type
35
     */
36 2
    public function run(Client $client, $index, $type)
37
    {
38 2
        $this->client = $client;
39 2
        $this->index  = $index;
40 2
        $this->type   = $type;
41
        
42 2
        $this->populate();
43 2
    }
44
45
    /**
46
     * Populate
47
     *
48
     * @return null
49
     */
50
    abstract public function populate();
51
52
    /**
53
     * Index document
54
     *
55
     * @param string $id
56
     * @param array  $body
57
     */
58 1
    public function index($id, array $body)
59
    {
60 1
        $this->client->index([
61 1
            'index' => $this->index,
62 1
            'type'  => $this->type,
63 1
            'id'    => $id,
64 1
            'body'  => $body,
65 1
        ]);
66
    }
67
}