Completed
Push — master ( fbc1fa...9bba21 )
by
unknown
14s
created

IndexConfig::isUseAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
/**
13
 * This file is part of the FOSElasticaBundle project.
14
 *
15
 * (c) Tim Nagel <[email protected]>
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 */
20
21
namespace FOS\ElasticaBundle\Configuration;
22
23
class IndexConfig
24
{
25
    /**
26
     * The name of the index for ElasticSearch.
27
     *
28
     * @var string
29
     */
30
    private $elasticSearchName;
31
32
    /**
33
     * The internal name of the index. May not be the same as the name used in ElasticSearch,
34
     * especially if aliases are enabled.
35
     *
36
     * @var string
37
     */
38
    private $name;
39
40
    /**
41
     * An array of settings sent to ElasticSearch when creating the index.
42
     *
43
     * @var array
44
     */
45
    private $settings;
46
47
    /**
48
     * All types that belong to this index.
49
     *
50
     * @var TypeConfig[]
51
     */
52
    private $types;
53
54
    /**
55
     * Indicates if the index should use an alias, allowing an index repopulation to occur
56
     * without overwriting the current index.
57
     *
58
     * @var bool
59
     */
60
    private $useAlias = false;
61
62
    /**
63
     * Constructor expects an array as generated by the Container Configuration builder.
64
     *
65
     * @param string       $name
66
     * @param TypeConfig[] $types
67
     * @param array        $config
68
     */
69
    public function __construct($name, array $types, array $config)
70
    {
71
        $this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name;
72
        $this->name = $name;
73
        $this->settings = isset($config['settings']) ? $config['settings'] : [];
74
        $this->types = $types;
75
        $this->useAlias = isset($config['useAlias']) ? $config['useAlias'] : false;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getElasticSearchName()
82
    {
83
        return $this->elasticSearchName;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getName()
90
    {
91
        return $this->name;
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getSettings()
98
    {
99
        return $this->settings;
100
    }
101
102
    /**
103
     * @param string $typeName
104
     *
105
     * @return TypeConfig
106
     *
107
     * @throws \InvalidArgumentException
108
     */
109
    public function getType($typeName)
110
    {
111
        if (!array_key_exists($typeName, $this->types)) {
112
            throw new \InvalidArgumentException(sprintf('Type "%s" does not exist on index "%s"', $typeName, $this->name));
113
        }
114
115
        return $this->types[$typeName];
116
    }
117
118
    /**
119
     * @return \FOS\ElasticaBundle\Configuration\TypeConfig[]
120
     */
121
    public function getTypes()
122
    {
123
        return $this->types;
124
    }
125
126
    /**
127
     * @return bool
128
     */
129
    public function isUseAlias()
130
    {
131
        return $this->useAlias;
132
    }
133
}
134