1 | <?php |
||||
2 | |||||
3 | |||||
4 | namespace Thinkone\NovaPageSettings\QueryAdapter; |
||||
5 | |||||
6 | use Illuminate\Database\Query\Builder as QueryBuilder; |
||||
7 | use Illuminate\Support\Str; |
||||
8 | use ReflectionClass; |
||||
9 | use Symfony\Component\Finder\Finder; |
||||
10 | use Thinkone\NovaPageSettings\Templates\SettingsTemplate; |
||||
11 | |||||
12 | class InternalSettingsQueryBuilder extends QueryBuilder |
||||
13 | { |
||||
14 | protected array $_templates = []; |
||||
15 | protected array $_templatesCompiled = []; |
||||
16 | |||||
17 | 3 | protected function runSelect(): array |
|||
18 | { |
||||
19 | 3 | if (empty($this->_templatesCompiled)) { |
|||
20 | 3 | $this->_templatesCompiled = collect($this->getTemplates()) |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
21 | 3 | /** @var SettingsTemplate $template */ |
|||
22 | 3 | ->map(function ($template, $id) { |
|||
23 | 3 | return [ |
|||
24 | 3 | InternalSettingsModel::ATTR_CLASS => $template, |
|||
25 | 3 | InternalSettingsModel::ATTR_ID => method_exists($template, 'getID')?$template::getID():$id, |
|||
26 | 3 | InternalSettingsModel::ATTR_NAME => $template::getName(), |
|||
27 | 3 | ]; |
|||
28 | 3 | })->toArray(); |
|||
29 | } |
||||
30 | |||||
31 | 3 | return $this->_templatesCompiled; |
|||
32 | } |
||||
33 | |||||
34 | 1 | public function getCountForPagination($columns = [ '*' ]): int |
|||
35 | { |
||||
36 | 1 | $templates = $this->getTemplates(); |
|||
37 | |||||
38 | 1 | return count($templates); |
|||
39 | } |
||||
40 | |||||
41 | 3 | public function getTemplates() |
|||
42 | { |
||||
43 | 3 | if (empty($this->_templates)) { |
|||
44 | 3 | $namespace = app()->getNamespace(); |
|||
0 ignored issues
–
show
The method
getNamespace() does not exist on Illuminate\Container\Container . Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
45 | 3 | $templates = []; |
|||
46 | 3 | if(Str::startsWith($this->from, DIRECTORY_SEPARATOR)) { |
|||
47 | 3 | $from = $this->from; |
|||
48 | } else { |
||||
49 | $from = base_path($this->from); |
||||
50 | } |
||||
51 | 3 | foreach (( new Finder )->in($from)->files() as $template) { |
|||
52 | 3 | preg_match('/\s*namespace\s?([A-Za-z\\\]*)\s*;\s*/is', file_get_contents($template->getPathname()), $matches); |
|||
53 | 3 | if(isset($matches[1])) { |
|||
54 | 3 | $namespace = '\\'.$matches[1]; |
|||
55 | } |
||||
56 | |||||
57 | 3 | $template = $namespace . '\\' . Str::before($template->getBasename(), '.'.$template->getExtension()); |
|||
58 | |||||
59 | 3 | if (class_implements($template, SettingsTemplate::class) && |
|||
0 ignored issues
–
show
Thinkone\NovaPageSetting...SettingsTemplate::class of type string is incompatible with the type boolean expected by parameter $autoload of class_implements() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
60 | 3 | !( new ReflectionClass($template) )->isAbstract()) { |
|||
61 | 3 | $templates[] = $template; |
|||
62 | } |
||||
63 | } |
||||
64 | |||||
65 | 3 | $this->_templates = $templates; |
|||
66 | } |
||||
67 | |||||
68 | 3 | return $this->_templates; |
|||
69 | } |
||||
70 | } |
||||
71 |