-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeViewFinder.php
99 lines (86 loc) · 3.02 KB
/
ThemeViewFinder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Litepie\Theme;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\FileViewFinder;
use Illuminate\View\ViewFinderInterface;
use InvalidArgumentException;
use Theme;
class ThemeViewFinder extends FileViewFinder implements ViewFinderInterface
{
public function __construct(Filesystem $files, array $paths, array $extensions = null)
{
parent::__construct($files, $paths, $extensions);
}
/*
* Override findNamespacedView() to add "theme/view/vendor/..." paths
*
* @param string $name
* @return string
*/
protected function findNamespacedView($name)
{
// Extract the $view and the $namespace parts
list($namespace, $view) = $this->parseNamespaceSegments($name);
// Add possible view folders based of the route
if (count($this->hints[$namespace]) < 3) {
$hintPath = $this->hints[$namespace][0];
$resoPath = resource_path('views/vendor/').$namespace;
$themPath = public_path(app('theme')->path().'/views/vendor/'.$namespace);
$defaFolder = $this->getDefaultFolder();
$viewFolder = $this->getViewFolder();
$this->prependNamespace($namespace, $hintPath.'/'.$defaFolder);
$this->prependNamespace($namespace, $hintPath.'/'.$viewFolder);
$this->prependNamespace($namespace, $resoPath);
$this->prependNamespace($namespace, $resoPath.'/'.$defaFolder);
$this->prependNamespace($namespace, $resoPath.'/'.$viewFolder);
$this->prependNamespace($namespace, $themPath);
}
return $this->findInPaths($view, $this->hints[$namespace]);
}
/**
* Find the given view in the list of paths.
*
* @param string $name
* @param array $paths
*
* @throws \InvalidArgumentException
*
* @return string
*/
protected function findInPaths($name, $paths)
{
$location = public_path(app('theme')->path().'/views');
array_unshift($paths, $location);
foreach ((array) $paths as $path) {
if (!$this->files->exists($path)) {
continue;
}
foreach ($this->getPossibleViewFiles($name) as $file) {
if ($this->files->exists($viewPath = $path.'/'.$file)) {
return $viewPath;
}
}
}
throw new InvalidArgumentException("View [$name] not found.");
}
/**
* Return folder for current guard.
*
* @return type
*/
private function getViewFolder()
{
$guard = substr(guard(), 0, strpos(guard(), '.'));
return config('theme.themes.'.$guard.'.view', config('theme.themes.default.view', $guard));
}
/**
* Return default folder for current guard.
*
* @return type
*/
private function getDefaultFolder()
{
$guard = substr(guard(), 0, strpos(guard(), '.'));
return config('theme.themes.'.$guard.'.default', config('theme.themes.default.default', 'default'));
}
}