1 | <?php |
||
7 | class WidgetRenderer |
||
8 | { |
||
9 | public $html; |
||
10 | |||
11 | private $_viewData; |
||
12 | |||
13 | private $_policies; |
||
14 | |||
15 | /** |
||
16 | * BaseWidget constructor. |
||
17 | */ |
||
18 | 13 | public function __construct() |
|
22 | |||
23 | /** |
||
24 | * @param $widget object|string |
||
25 | * @param array $args |
||
26 | * @return string |
||
27 | */ |
||
28 | 13 | public function renderWidget($widget, ...$args) |
|
29 | { |
||
30 | 13 | if (is_string($widget)) { |
|
31 | 1 | $widget = $this->makeWidgetObj($widget); |
|
32 | } |
||
33 | |||
34 | 13 | app(Normalizer::class)->normalizeWidgetConfig($widget); |
|
35 | |||
36 | 13 | if (app()->offsetExists('debugbar')) { |
|
37 | app('widgetize.debugger')->addMessage(['widget class:' => $widget, 'args:' => $args]); |
||
38 | } |
||
39 | |||
40 | try { |
||
41 | 13 | $html = $this->generateHtml($widget, ...$args); |
|
42 | } catch (\Exception $e) { |
||
43 | return app()->make(ExceptionHandler::class)->render(app('request'), $e)->send(); |
||
44 | } |
||
45 | |||
46 | 13 | return $html; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param $widget object |
||
51 | * @return \Illuminate\Foundation\Application|mixed |
||
52 | */ |
||
53 | 1 | private function makeWidgetObj($widget) |
|
54 | { |
||
55 | 1 | if (starts_with($widget, ['\\'])) { |
|
56 | return app($widget); |
||
57 | } |
||
58 | |||
59 | 1 | $widget = app()->getNamespace().'Widgets\\'.$widget; |
|
60 | |||
61 | 1 | return app($widget); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * It tries to get the html from cache if possible, otherwise generates it. |
||
66 | * |
||
67 | * @param $widget object |
||
68 | * @param array ...$args |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | private function generateHtml($widget, ...$args) |
||
89 | |||
90 | /** |
||
91 | * @param $widget object |
||
92 | * @param $args array |
||
93 | * |
||
94 | * @return null |
||
95 | */ |
||
96 | 11 | private function makeDataForView($widget, array $args) |
|
109 | |||
110 | /** |
||
111 | * @param $widget object |
||
112 | * @return string HTML output |
||
113 | */ |
||
114 | 11 | private function renderTemplate($widget) |
|
132 | } |
||
133 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: