Completed
Push — master ( 85f2e1...d1e37b )
by Sebastian
04:23
created

TranslationLoader::fetchFragments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace App\Services\Locale;
4
5
use App\Models\Fragment;
6
use Cache;
7
use Illuminate\Translation\FileLoader;
8
use Schema;
9
10
class TranslationLoader extends FileLoader
11
{
12
    /**
13
     * Load the messages for the given locale.
14
     *
15
     * @param  string $locale
16
     * @param  string $group
17
     * @param  string $namespace
18
     *
19
     * @return array
20
     */
21
    public function load($locale, $group, $namespace = null) : array
22
    {
23
        if (!is_null($namespace) && $namespace !== '*') {
24
            return $this->loadNamespaced($locale, $group, $namespace);
25
        }
26
27
        if (!$this->fragmentsAreAvailable()) {
28
            return [];
29
        }
30
31
        return Cache::rememberForever(
32
            "locale.fragments.{$locale}.{$group}",
33
            function () use ($group, $locale) {
34
                return Fragment::getGroup($group, $locale);
35
            }
36
        );
37
    }
38
39
    protected function fragmentsAreAvailable() : bool
40
    {
41
        try {
42
            return Schema::hasTable('fragments');
43
        } catch (\Exception $e) {
44
            return false;
45
        }
46
    }
47
}
48