@@ -28,40 +28,24 @@ class ContentRendererServiceProvider extends ServiceProvider
28
28
public function register (): void
29
29
{
30
30
// Boot Default
31
- $ this ->registerDefaultRenderer ();
32
-
33
- // Boot Factory
34
- $ this ->app ->singleton (Factory::class, function (Application $ app ) {
35
- $ factory = new Factory ($ app ->make (ContentRendererInterface::class));
36
-
37
- $ factory ->extend (Type::MENU , static function () use ($ app ) {
38
- return new MenuRenderer ($ app ->make (DispatcherInterface::class));
39
- });
40
-
41
- $ factory ->extend (Type::MENU_TRANSLATION , static function () use ($ app ) {
42
- return new MenuTranslationRenderer ($ app ->make (DispatcherInterface::class));
43
- });
44
-
45
- $ factory ->extend (Type::DOCUMENTATION , static function () use ($ app ) {
46
- return new DocumentationRenderer ($ app ->make (DispatcherInterface::class));
47
- });
48
-
49
- $ factory ->extend (Type::DOCUMENTATION_TRANSLATION , static function () use ($ app ) {
50
- return new DocumentationTranslationRenderer ($ app ->make (DispatcherInterface::class));
51
- });
52
-
53
- return $ factory ;
31
+ $ this ->app ->singleton (DefaultRenderer::class);
32
+ $ this ->app ->singleton (MenuRenderer::class);
33
+ $ this ->app ->singleton (MenuTranslationRenderer::class);
34
+ $ this ->app ->singleton (DocumentationRenderer::class);
35
+ $ this ->app ->singleton (DocumentationTranslationRenderer::class);
36
+
37
+ $ this ->app ->singleton (Factory::class, function (Application $ app ): Factory {
38
+ $ default = $ app ->make (ContentRendererInterface::class);
39
+
40
+ return new Factory ($ default , value (static function () use ($ app ): iterable {
41
+ yield Type::MENU => $ app ->make (MenuRenderer::class);
42
+ yield Type::MENU_TRANSLATION => $ app ->make (MenuTranslationRenderer::class);
43
+ yield Type::DOCUMENTATION => $ app ->make (DocumentationRenderer::class);
44
+ yield Type::DOCUMENTATION_TRANSLATION => $ app ->make (DocumentationTranslationRenderer::class);
45
+ }));
54
46
});
55
47
56
- $ this ->app ->alias (Factory::class, FactoryInterface::class);
57
- }
58
-
59
- /**
60
- * @return void
61
- */
62
- private function registerDefaultRenderer (): void
63
- {
64
- $ this ->app ->singleton (DefaultRenderer::class);
65
48
$ this ->app ->alias (DefaultRenderer::class, ContentRendererInterface::class);
49
+ $ this ->app ->alias (Factory::class, FactoryInterface::class);
66
50
}
67
51
}
0 commit comments