Completed
Push — master ( 71a6c0...245242 )
by François
02:26
created

Standard::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[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 Bouncer\Profile;
13
14
use Bouncer\Bouncer;
15
16
class DefaultProfile
17
{
18
19
    public function load(Bouncer $instance)
20
    {
21
        self::loadAnalyzers($instance);
22
23
        self::initCache($instance);
24
    }
25
26
    public function loadAnalyzers(Bouncer $instance)
27
    {
28
        // Load Default analyzers
29
        \Bouncer\Analyzer\Hostname::load($instance);
30
    }
31
32
    public function initCache(Bouncer $instance)
33
    {
34
        // If no cache available, try to set up APC
35
        $cache = $instance->getCache();
36
        if (empty($cache)) {
37
            if (function_exists('apc_fetch')) {
38
                $cache = new \Bouncer\Cache\Apc();
39
                $instance->setOptions(array('cache' => $cache));
40
            } else {
41
                $instance->error('No cache available. A cache is needed to keep performances acceptable.');
42
            }
43
        }
44
    }
45
46
}
47