Completed
Push — master ( 6ed010...811bc4 )
by Karel
06:34 queued 10s
created

PersisterRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
namespace FOS\ElasticaBundle\Persister;
13
14
use Symfony\Component\DependencyInjection\ServiceLocator;
15
16
class PersisterRegistry
17
{
18
    /**
19
     * @var ServiceLocator
20
     */
21
    private $persisters = [];
22
23 1
    public function __construct(ServiceLocator $persisters)
24
    {
25 1
        $this->persisters = $persisters;
26 1
    }
27
28
    /**
29
     * Gets the persister for an index.
30
     *
31
     * @throws \InvalidArgumentException if no persister was registered for the index
32
     */
33 1
    public function getPersister(string $index): ObjectPersisterInterface
34
    {
35 1
        if (!$this->persisters->has($index)) {
36
            throw new \InvalidArgumentException(sprintf('No persister was registered for index "%s".', $index));
37
        }
38
39 1
        return $this->persisters->get($index);
40
    }
41
}
42