1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin; |
4
|
|
|
|
5
|
|
|
use Route; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use SleepingOwl\Admin\Contracts\Navigation\PageInterface; |
8
|
|
|
use SleepingOwl\Admin\Contracts\Navigation\NavigationInterface; |
9
|
|
|
|
10
|
|
|
class Navigation extends \KodiComponents\Navigation\Navigation implements NavigationInterface |
11
|
|
|
{ |
12
|
|
|
protected $currentPage; |
13
|
|
|
protected $currentUrl; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Overload current page. |
17
|
|
|
* @return \KodiComponents\Navigation\Contracts\PageInterface|null |
18
|
|
|
*/ |
19
|
|
|
public function getCurrentPage() |
20
|
|
|
{ |
21
|
|
|
$this->setAliasesId($this->getPages()); |
|
|
|
|
22
|
|
|
$this->findActivePage(); |
23
|
|
|
|
24
|
|
|
return $this->currentPage; |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Set Alias Id to Page. |
29
|
|
|
* @param Collection $pages |
30
|
|
|
*/ |
31
|
|
|
public function setAliasesId(Collection $pages) |
32
|
|
|
{ |
33
|
|
|
$pages->each(function (PageInterface $page) { |
34
|
|
|
$page->setAliasId(); |
35
|
|
|
|
36
|
|
|
if ($page->getPages()->count()) { |
37
|
|
|
$this->setAliasesId($page->getPages()); |
38
|
|
|
} |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $url |
44
|
|
|
* @param array $foundPages |
45
|
|
|
*/ |
46
|
|
|
protected function findActive($url, array &$foundPages) |
47
|
|
|
{ |
48
|
|
|
$this->findPageByAliasId($this->getPages(), $url); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param Collection $pages |
53
|
|
|
* @param $url |
54
|
|
|
*/ |
55
|
|
|
protected function findPageByAliasId(Collection $pages, $url) |
56
|
|
|
{ |
57
|
|
|
$pages->each(function (PageInterface $page) use ($url) { |
58
|
|
|
$urlPath = parse_url($url, PHP_URL_PATH); |
59
|
|
|
|
60
|
|
|
if (Route::current()) { |
61
|
|
|
$parameters = collect(Route::current()->parameters()); |
62
|
|
|
|
63
|
|
|
if ($parameters->has('adminModelId')) { |
64
|
|
|
$routeUrl = route('admin.model', [ |
65
|
|
|
'adminModel' => snake_case(class_basename($parameters->get('adminModel'))), |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$urlPath = parse_url($routeUrl, PHP_URL_PATH); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($urlPath) { |
|
|
|
|
73
|
|
|
if (md5($urlPath) == $page->getAliasId()) { |
74
|
|
|
$this->currentPage = $page; |
75
|
|
|
|
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->findPageByAliasId($page->getPages(), $url); |
81
|
|
|
}); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
protected function findActivePage() |
88
|
|
|
{ |
89
|
|
|
if (! is_null($this->currentPage)) { |
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$foundPages = []; |
94
|
|
|
|
95
|
|
|
$url = $this->getCurrentUrl(); |
96
|
|
|
|
97
|
|
|
$this->findActive($url, $foundPages); |
98
|
|
|
|
99
|
|
|
if (! is_null($this->currentPage)) { |
100
|
|
|
$this->currentPage->setActive(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (config('navigation.aliases')) { |
104
|
|
|
$this->findActiveByAliases( |
105
|
|
|
ltrim(parse_url($url, PHP_URL_PATH), '/') |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return false; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.