Test Failed
Pull Request — master (#12)
by Maximo
03:04
created

SessionProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 34
ccs 14
cts 14
cp 1
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 15
    public function register(DiInterface $container)
17
    {
18 15
        $config = $container->getShared('config');
19
20 15
        $container->setShared(
21 15
            'session',
22
            function () use ($config) {
23
                $backOptions = [
24 1
                    'servers' => [
25
                        0 => [
26 1
                            'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
27 1
                            'port' => envValue('DATA_API_MEMCACHED_PORT', 11211),
28 1
                            'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
29
                        ],
30
                    ],
31
                    'client' => [
32
                        Memcached::OPT_HASH => Memcached::HASH_MD5,
33 1
                        Memcached::OPT_PREFIX_KEY => 'bakasession' . $config->app->id . '-',
34
                    ],
35 1
                    'lifetime' => 8600,
36 1
                    'prefix' => 'bakasession' . $config->app->id . '-',
37
                    'persistent' => false
38
                ];
39
40 1
                $memcache = new Libmemcached($backOptions);
41
42 1
                $memcache->start();
43
44 1
                return $memcache;
45 15
            }
46
        );
47 15
    }
48
}
49