Skip to content

Commit a456e7d

Browse files
Merge pull request #61 from hexadog/develop
Develop
2 parents cd7d4fa + 2dff43d commit a456e7d

File tree

4 files changed

+47
-44
lines changed

4 files changed

+47
-44
lines changed

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
],
1515
"minimum-stability": "stable",
1616
"require": {
17+
"php": ">=7.4",
18+
"ext-json": "*",
1719
"hexadog/laravel-theme-installer": "^1.0",
1820
"illuminate/view": "^7.0|^8.0|^9.0|^10.0"
1921
},

src/Helpers/Json.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ public function save(): bool
201201
/**
202202
* Get the specified attribute from json file.
203203
*
204-
* @param null $default
204+
* @param null $default
205+
* @param mixed $key
205206
*
206207
* @return mixed
207208
*/

src/Theme.php

-43
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,6 @@ public function getAssetsPath(string $path = null): string
9999
return Config::get('themes-manager.symlink_path', 'themes') . '/' . mb_strtolower($this->vendor) . '/' . mb_strtolower($this->name) . ($path ? '/' . $path : '');
100100
}
101101

102-
/**
103-
* Get theme views paths.
104-
* Build Paths array.
105-
* All paths are relative to Config::get('themes-manager.directory').
106-
*/
107-
public function getViewPaths(string $path = ''): array
108-
{
109-
$paths = [];
110-
$theme = $this;
111-
112-
do {
113-
$viewsPath = $theme->getPath('resources/views' . ($path ? "/{$path}" : ''));
114-
115-
if (!in_array($viewsPath, $paths)) {
116-
$paths[] = $viewsPath;
117-
}
118-
} while ($theme = $theme->getParent());
119-
120-
return array_reverse($paths);
121-
}
122-
123102
/**
124103
* Set extra data.
125104
*/
@@ -356,28 +335,6 @@ public function url(string $url, bool $absolute = true): string
356335
return ltrim(str_replace('\\', '/', $url));
357336
}
358337

359-
/**
360-
* List theme's available layouts.
361-
*
362-
* @return \Illuminate\Support\Collection
363-
*/
364-
public function listLayouts()
365-
{
366-
$layouts = collect();
367-
368-
$layoutDirs = $this->getViewPaths('layouts');
369-
370-
foreach ($layoutDirs as $layoutDir) {
371-
if ($layoutFiles = glob($layoutDir . '/{**/*,*}.php', GLOB_BRACE)) {
372-
foreach ($layoutFiles as $layout) {
373-
$layouts->put($layout, basename($layout, '.blade.php'));
374-
}
375-
}
376-
}
377-
378-
return $layouts;
379-
}
380-
381338
/**
382339
* Create public assets directory path.
383340
*/

src/Traits/HasViews.php

+43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,49 @@
99

1010
trait HasViews
1111
{
12+
/**
13+
* Get theme views paths.
14+
* Build Paths array.
15+
* All paths are relative to Config::get('themes-manager.directory').
16+
*/
17+
public function getViewPaths(string $path = ''): array
18+
{
19+
$paths = [];
20+
$theme = $this;
21+
22+
do {
23+
$viewsPath = $theme->getPath('resources/views' . ($path ? "/{$path}" : ''));
24+
25+
if (!in_array($viewsPath, $paths)) {
26+
$paths[] = $viewsPath;
27+
}
28+
} while ($theme = $theme->getParent());
29+
30+
return $paths;
31+
}
32+
33+
/**
34+
* List theme's available layouts.
35+
*
36+
* @return \Illuminate\Support\Collection
37+
*/
38+
public function listLayouts()
39+
{
40+
$layouts = collect();
41+
42+
$layoutDirs = $this->getViewPaths('layouts');
43+
44+
foreach ($layoutDirs as $layoutDir) {
45+
if ($layoutFiles = glob($layoutDir . '/{**/*,*}.php', GLOB_BRACE)) {
46+
foreach ($layoutFiles as $layout) {
47+
$layouts->put($layout, basename($layout, '.blade.php'));
48+
}
49+
}
50+
}
51+
52+
return $layouts;
53+
}
54+
1255
/**
1356
* Register theme's views in ViewFinder.
1457
*/

0 commit comments

Comments
 (0)