Failed Conditions
Pull Request — master (#10)
by Maximo
03:34
created

SessionProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 34
ccs 4
cts 14
cp 0.2857
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 29 1
1
<?php
2
3
namespace Gewaer\Providers;
4
5
use function Gewaer\Core\envValue;
6
use Phalcon\Di\ServiceProviderInterface;
7
use Phalcon\DiInterface;
8
use Memcached;
9
use Phalcon\Session\Adapter\Libmemcached;
10
11
class SessionProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * @param DiInterface $container
15
     */
16 4
    public function register(DiInterface $container)
17
    {
18 4
        $config = $container->getShared('config');
19
20 4
        $container->setShared(
21 4
            'session',
22
            function () use ($config) {
23
                $backOptions = [
24
                    'servers' => [
25
                        0 => [
26
                            'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
27
                            'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
28
                            'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
29
                        ],
30
                    ],
31
                    'client' => [
32
                        Memcached::OPT_HASH => Memcached::HASH_MD5,
33
                        Memcached::OPT_PREFIX_KEY => 'bakasession' . $config->app->id . '-',
34
                    ],
35
                    'lifetime' => 8600,
36
                    'prefix' => 'bakasession' . $config->app->id . '-',
37
                    'persistent' => false
38
                ];
39
40
                $memcache = new Libmemcached($backOptions);
41
42
                $memcache->start();
43
44
                return $memcache;
45 4
            }
46
        );
47 4
    }
48
}
49