Completed
Push — master ( 145693...9a5594 )
by Peter
06:17
created

GpsLabGeoIP2Extension::load()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 13
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 4
nop 2
crap 12
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2017, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\GeoIP2Bundle\DependencyInjection;
11
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\Config\FileLocator;
14
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15
use Symfony\Component\DependencyInjection\Loader;
16
17
class GpsLabGeoIP2Extension extends Extension
18
{
19
    public function load(array $configs, ContainerBuilder $container)
20
    {
21
        $config = $this->processConfiguration(new Configuration(), $configs);
22
23
        if (empty($config['cache'])) {
24
            $config['cache'] = $container->getParameter('kernel.cache_dir').'GeoLite2-Country.mmdb';
25
        }
26
27
        if (empty($config['url'])) {
28
            $config['url'] = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz';
29
        }
30
31
        $container->setParameter('geoip2.cache', $config['cache']);
32
        $container->setParameter('geoip2.url', $config['url']);
33
34
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35
        $loader->load('services.yml');
36
    }
37
}
38