TranslationLoader::load()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 3
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Locale;
4
5
use Cache;
6
use Schema;
7
use App\Models\Fragment;
8
use Illuminate\Translation\FileLoader;
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
        static $fragmentTableFound = null;
42
43
        if (is_null($fragmentTableFound)) {
44
            try {
45
                $fragmentTableFound = Schema::hasTable('fragments');
46
            } catch (\Exception $e) {
47
                $fragmentTableFound = false;
48
            }
49
        }
50
51
        return $fragmentTableFound;
52
    }
53
}
54