FileLoaderResolver::hasLoader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the AsmTranslationLoaderBundle package.
5
 *
6
 * (c) Marc Aschmann <[email protected]>
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 Asm\TranslationLoaderBundle\Translation;
13
14
use Symfony\Component\Translation\Loader\LoaderInterface;
15
16
/**
17
 * Translation loader resolver.
18
 *
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class FileLoaderResolver
22
{
23
    /**
24
     * @var LoaderInterface[]
25
     */
26
    private $loaders = array();
27
28
    /**
29
     * @param LoaderInterface $loader    The translation loader
30
     * @param string          $extension The file extension
31
     */
32 14
    public function registerLoader(LoaderInterface $loader, $extension)
33
    {
34 14
        $this->loaders[$extension] = $loader;
35 14
    }
36
37
    /**
38
     * Checks whether or not a translation loader for a file extension is registered.
39
     *
40
     * @param string $extension The file extension
41
     *
42
     * @return boolean True if such a loader is registered, false otherwise
43
     */
44 14
    public function hasLoader($extension)
45
    {
46 14
        return isset($this->loaders[$extension]);
47
    }
48
49
    /**
50
     * Resolves the translation loader for a file extension.
51
     *
52
     * @param string $extension The file extension
53
     *
54
     * @return LoaderInterface The resolved loader or null if no loader is
55
     *                         associated with the given extension
56
     */
57 14
    public function resolveLoader($extension)
58
    {
59 14
        if ($this->hasLoader($extension)) {
60 13
            return $this->loaders[$extension];
61
        }
62
63 1
        return null;
64
    }
65
}
66