File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -113,16 +113,14 @@ protected function instantiateWidget(array $params = [])
113113
114114 $ rootNamespace = $ this ->app ->config ('laravel-widgets.default_namespace ' , $ this ->app ->getNamespace ().'Widgets ' );
115115
116- $ widgetClass = class_exists ($ this ->widgetName )
117- ? $ this ->widgetName
118- : $ rootNamespace .'\\' .$ this ->widgetName ;
116+ $ fqcn = $ rootNamespace .'\\' .$ this ->widgetName ;
117+ $ widgetClass = class_exists ($ fqcn ) ? $ fqcn : $ this ->widgetName ;
119118
120- $ widget = new $ widgetClass ($ this ->widgetConfig );
121- if ($ widget instanceof AbstractWidget === false ) {
122- throw new InvalidWidgetClassException ();
119+ if (!is_subclass_of ($ widgetClass , 'Arrilot\Widgets\AbstractWidget ' )) {
120+ throw new InvalidWidgetClassException ('Class " ' .$ widgetClass .'" must extend "Arrilot\Widgets\AbstractWidget" class ' );
123121 }
124122
125- $ this ->widget = $ widget ;
123+ $ this ->widget = new $ widgetClass ( $ this -> widgetConfig ) ;
126124 }
127125
128126 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Arrilot \Widgets \Test \Dummies ;
4+
5+ use Arrilot \Widgets \AbstractWidget ;
6+
7+ class Exception extends AbstractWidget
8+ {
9+ public function run ()
10+ {
11+ return "Exception widget was executed instead of predefined php class " ;
12+ }
13+ }
Original file line number Diff line number Diff line change @@ -69,6 +69,13 @@ public function testItCanRunWidgetsUsingFQCN()
6969 $ this ->assertEquals ('Default test slider was executed with $slides = 6 ' , $ output );
7070 }
7171
72+ public function testItLoadsWidgetsFromRootNamespaceFirst ()
73+ {
74+ $ output = $ this ->factory ->run ('Exception ' );
75+
76+ $ this ->assertEquals ('Exception widget was executed instead of predefined php class ' , $ output );
77+ }
78+
7279 public function testItCanRunNestedWidgets ()
7380 {
7481 $ output = $ this ->factory ->run ('Profile\TestNamespace\TestFeed ' );
You can’t perform that action at this time.
0 commit comments