countAvailableLocales()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sleepness\UberTranslationBundle\DataCollector;
4
5
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Sleepness\UberTranslationBundle\Storage\UberMemcached;
9
10
/**
11
 * Collect translations from Memcache to Symfony profiler
12
 *
13
 * @author Viktor Novikov <[email protected]>
14
 */
15
class UberTranslationsDataCollector extends DataCollector
16
{
17
    /**
18
     * @var UberMemcached $uberMemcached
19
     */
20
    private $uberMemcached;
21
22
    /**
23
     * @param UberMemcached $uberMemcached
24
     */
25
    public function __construct(UberMemcached $uberMemcached)
26
    {
27
        $this->uberMemcached = $uberMemcached;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function collect(Request $request, Response $response, \Exception $exception = null)
34
    {
35
        $memcachedKeys = $this->uberMemcached->getAllKeys();
36
        $catalogues = array(); // prepare array for catalogues
37
        foreach ($memcachedKeys as $key) { // run through locales
38
            $catalogues[$key] = $this->uberMemcached->getItem($key);
39
        }
40
        $this->data = array(
41
            'memcached_translations' => $catalogues,
42
        );
43
    }
44
45
    /**
46
     * Allow fetch memcached translation in data collector template
47
     *
48
     * @return array
49
     */
50
    public function getTranslations()
51
    {
52
        return $this->data['memcached_translations'];
53
    }
54
55
    /**
56
     * Allow get count of available locales in collector template
57
     *
58
     * @return number
59
     */
60
    public function countAvailableLocales()
61
    {
62
        return count($this->data['memcached_translations']);
63
    }
64
65
    /**
66
     * Return collector name
67
     *
68
     * @return string
69
     */
70
    public function getName()
71
    {
72
        return 'uber_translations_collector';
73
    }
74
}
75