Completed
Push — master ( 0d16be...215ca2 )
by Scott
01:59
created

BackendController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Bedard\Shop\Classes;
2
3
use Backend\Classes\Controller as BaseController;
4
use Lang;
5
6
class BackendController extends BaseController
7
{
8
    public function __construct()
9
    {
10
        parent::__construct();
11
12
        $this->addJs('/plugins/bedard/shop/assets/dist/vendor.js');
13
    }
14
15
    /**
16
     * Get a set of language strings and convert them to JSON.
17
     *
18
     * @param  array    $keys
19
     * @return string
20
     */
21
    public function getLangJson($keys)
22
    {
23
        $lang = [];
24
25
        foreach ($keys as $key => $value) {
26
            $isFiltered = gettype($value) === 'array';
27
28
            if (! $isFiltered) {
29
                $key = $value;
30
            }
31
32
            $alias = explode('@', $key);
33
            $languageString = $alias[count($alias) - 1];
34
35
            $lang[$alias[0]] = $isFiltered
36
                ? array_intersect_key(Lang::get($languageString), array_flip($value))
37
                : Lang::get($languageString);
38
        }
39
40
        return json_encode($lang);
41
    }
42
}
43