Skip to content

Commit f88d13e

Browse files
UnderlineWordskaidesu
authored andcommitted
Added byLocation() method (#410)
* Added byLocation() method * Added byLocation() method.
1 parent a0cfd38 commit f88d13e

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/Contracts/Repository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,13 @@ public function enable($slug);
148148
* @return bool
149149
*/
150150
public function disable($slug);
151+
152+
/**
153+
* Get all modules by specified location
154+
*
155+
* @param string $location
156+
*
157+
* @return \Illuminate\Support\Collection
158+
*/
159+
public function byLocation($location);
151160
}

src/Repositories/LocalRepository.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,20 @@ public function disable($slug)
213213
{
214214
return $this->set($slug.'::enabled', false);
215215
}
216+
217+
/**
218+
* Get all modules by specified location
219+
*
220+
* @param string $location
221+
*
222+
* @return \Illuminate\Support\Collection
223+
*/
224+
public function byLocation($location)
225+
{
226+
$manifest = $this->getCachePath($location);
227+
228+
return collect(json_decode($this->files->get($manifest), true));
229+
}
216230

217231
/*
218232
|--------------------------------------------------------------------------
@@ -299,13 +313,13 @@ private function createCache()
299313
*
300314
* @return string
301315
*/
302-
private function getCachePath()
316+
private function getCachePath($location = null)
303317
{
304318
if (!$this->files->isDirectory(storage_path("app/modules"))) {
305319
$this->files->makeDirectory(storage_path("app/modules"));
306320
}
307321

308-
$location = Str::slug($this->location);
322+
$location = Str::slug($location ?? $this->location);
309323

310324
return storage_path("app/modules/$location.json");
311325
}

0 commit comments

Comments
 (0)