Skip to content

Commit ea247d4

Browse files
authored
Merge pull request #103 from RobertBoes/make-widgets-with-the-illuminate-container
Make widget classes with the Illuminate Container
2 parents 839f5c0 + b6ca8ae commit ea247d4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Factories/AbstractWidgetFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function instantiateWidget(array $params = [])
133133
throw new InvalidWidgetClassException('Class "'.$widgetClass.'" must extend "Arrilot\Widgets\AbstractWidget" class');
134134
}
135135

136-
$this->widget = new $widgetClass($this->widgetConfig);
136+
$this->widget = $this->app->make($widgetClass, ['config' => $this->widgetConfig]);
137137

138138
if (static::$allowOnlyWidgetsWithDisabledEncryption && $this->widget->encryptParams) {
139139
throw new EncryptException('Widget "'.$widgetClass.'" was not called properly');

tests/Support/TestApplicationWrapper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Arrilot\Widgets\Test\Support;
44

5+
use Arrilot\Widgets\AbstractWidget;
56
use Arrilot\Widgets\Contracts\ApplicationWrapperContract;
67
use Arrilot\Widgets\Factories\AsyncWidgetFactory;
78
use Arrilot\Widgets\Factories\WidgetFactory;
@@ -97,6 +98,12 @@ public function make($abstract, array $parameters = [])
9798
return new TestEncrypter();
9899
}
99100

101+
if (is_subclass_of($abstract, AbstractWidget::class)) {
102+
$app = \Illuminate\Container\Container::getInstance();
103+
104+
return $app->makeWith($abstract, $parameters);
105+
}
106+
100107
throw new InvalidArgumentException("Binding {$abstract} cannot be resolved while testing");
101108
}
102109
}

0 commit comments

Comments
 (0)