Issues (238)

src/Loaders/DatabaseLoader.php (1 issue)

1
<?php
2
3
namespace Translation\Loaders;
4
5
use Translation\Repositories\TranslationRepository;
6
7
class DatabaseLoader extends Loader
8
{
9
    /**
10
     *  The default locale.
11
     *
12
     * @var string
13
     */
14
    protected $defaultLocale;
15
16
    /**
17
     *  Translations repository.
18
     *
19
     * @var \Translation\Repositories\TranslationRepository
20
     */
21
    protected $translationRepository;
22
23
    /**
24
     *  Create a new mixed loader instance.
25
     *
26
     * @param string                                          $defaultLocale
27
     * @param \Translation\Repositories\TranslationRepository $translationRepository
28
     */
29
    public function __construct($defaultLocale, TranslationRepository $translationRepository)
30
    {
31
        parent::__construct($defaultLocale);
32
        $this->translationRepository = $translationRepository;
33
    }
34
35
    /**
36
     *  Load the messages strictly for the given locale.
37
     *
38
     * @param  string $locale
39
     * @param  string $group
40
     * @param  string $namespace
41
     * @return array
42
     */
43
    public function loadSource($locale, $group, $namespace = '*')
44
    {
45
        $dotArray = $this->translationRepository->loadSource($locale, $namespace, $group);
46
        $undot    = [];
47
        foreach ($dotArray as $item => $text) {
48
            array_set($undot, $item, $text);
49
        }
50
        return $undot;
51
    }
52
53
    /**
54
     *  Add a new namespace to the loader.
55
     *
56
     * @param  string $namespace
57
     * @param  string $hint
58
     * @return void
59
     */
60
    public function addNamespace($namespace, $hint)
61
    {
62
        $this->hints[$namespace] = $hint;
0 ignored issues
show
Bug Best Practice introduced by
The property hints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
63
    }
64
65
    /**
66
     * Add a new JSON path to the loader.
67
     *
68
     * @param  string $path
69
     * @return void
70
     */
71
    public function addJsonPath($path)
72
    {
73
        //
74
    }
75
76
    /**
77
     * Get an array of all the registered namespaces.
78
     *
79
     * @return array
80
     */
81
    public function namespaces()
82
    {
83
        return $this->hints;
84
    }
85
}
86