1 | <?php |
||
17 | class Repository |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * The instance of the config. |
||
22 | * |
||
23 | * @var \Longman\LaravelMultiLang\Config |
||
24 | */ |
||
25 | protected $config; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * The instance of the cache. |
||
30 | * |
||
31 | * @var \Illuminate\Cache\CacheManager |
||
32 | */ |
||
33 | protected $cache; |
||
34 | |||
35 | /** |
||
36 | * The instance of the database. |
||
37 | * |
||
38 | * @var \Illuminate\Database\DatabaseManager |
||
39 | */ |
||
40 | protected $db; |
||
41 | |||
42 | /** |
||
43 | * Create a new MultiLang instance. |
||
44 | * |
||
45 | * @param string $environment |
||
|
|||
46 | * @param array $config |
||
47 | * @param \Illuminate\Cache\CacheManager $cache |
||
48 | * @param \Illuminate\Database\DatabaseManager $db |
||
49 | */ |
||
50 | 27 | public function __construct(Config $config, Cache $cache, Database $db) |
|
56 | |||
57 | 5 | public function getCacheName($lang) |
|
61 | |||
62 | 18 | public function loadFromDatabase($lang) |
|
63 | { |
||
64 | 18 | $texts = $this->getDb()->table($this->getTableName()) |
|
65 | 18 | ->where('lang', $lang) |
|
66 | 18 | ->get(['key', 'value', 'lang', 'scope']); |
|
67 | |||
68 | 18 | $array = []; |
|
69 | 18 | foreach ($texts as $row) { |
|
70 | 12 | $array[$row->key] = $row->value; |
|
71 | 18 | } |
|
72 | 18 | return $array; |
|
73 | } |
||
74 | |||
75 | 2 | public function loadFromCache($lang) |
|
81 | |||
82 | 4 | public function storeInCache($lang, array $texts) |
|
87 | |||
88 | /** |
||
89 | * Check if we must load texts from cache |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 4 | public function existsInCache($lang) |
|
97 | |||
98 | /** |
||
99 | * Get a database connection instance. |
||
100 | * |
||
101 | * @return \Illuminate\Database\Connection |
||
102 | */ |
||
103 | 18 | protected function getDb() |
|
111 | |||
112 | /** |
||
113 | * Get a cache driver instance. |
||
114 | * |
||
115 | * @return \Illuminate\Contracts\Cache\Repository |
||
116 | */ |
||
117 | 4 | protected function getCache() |
|
125 | |||
126 | 4 | public function save($texts) |
|
127 | { |
||
128 | 4 | if (empty($texts)) { |
|
129 | 1 | return false; |
|
130 | } |
||
131 | |||
132 | 4 | $table = $this->getTableName(); |
|
133 | 4 | $locales = $this->config->get('locales', []); |
|
134 | |||
135 | 4 | foreach ($texts as $k => $v) { |
|
136 | 4 | foreach ($locales as $lang => $locale_data) { |
|
137 | 4 | $exists = $this->getDb()->table($table)->where([ |
|
138 | 4 | 'key' => $k, |
|
139 | 4 | 'lang' => $lang, |
|
140 | 4 | ])->first(); |
|
141 | |||
142 | 4 | if ($exists) { |
|
143 | 1 | continue; |
|
144 | } |
||
145 | |||
146 | 4 | $this->getDb()->table($table)->insert([ |
|
147 | 4 | 'key' => $k, |
|
148 | 4 | 'lang' => $lang, |
|
149 | 4 | 'value' => $v, |
|
150 | 4 | ]); |
|
151 | 4 | } |
|
152 | 4 | } |
|
153 | 4 | return true; |
|
154 | } |
||
155 | |||
156 | 19 | public function getTableName() |
|
161 | } |
||
162 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.