Container.php
2 years ago
ContainerConfigurationInterface.php
2 years ago
WordPressPopularPostsConfiguration.php
2 years ago
WordPressPopularPostsConfiguration.php
161 lines
| 1 | <?php |
| 2 | namespace WordPressPopularPosts\Container; |
| 3 | |
| 4 | use WordPressPopularPosts\{ Image, I18N, Output, Settings, Themer, Translate, WordPressPopularPosts }; |
| 5 | use WordPressPopularPosts\Admin\Admin; |
| 6 | use WordPressPopularPosts\Block\Widget\Widget as BlockWidget; |
| 7 | use WordPressPopularPosts\Front\Front; |
| 8 | use WordPressPopularPosts\Shortcode\ShortcodeLoader; |
| 9 | use WordPressPopularPosts\Rest\{ Controller, PostsEndpoint, TaxonomiesEndpoint, ThemesEndpoint, ThumbnailsEndpoint, ViewLoggerEndpoint, WidgetEndpoint }; |
| 10 | use WordPressPopularPosts\Widget\Widget; |
| 11 | |
| 12 | class WordPressPopularPostsConfiguration implements ContainerConfigurationInterface |
| 13 | { |
| 14 | /** |
| 15 | * Modifies the given dependency injection container. |
| 16 | * |
| 17 | * @since 5.0.0 |
| 18 | * @param Container $container |
| 19 | */ |
| 20 | public function modify(Container $container) |
| 21 | { |
| 22 | $container['admin_options'] = Settings::get('admin_options'); |
| 23 | $container['widget_options'] = Settings::get('widget_options'); |
| 24 | |
| 25 | $container['i18n'] = $container->service(function(Container $container) { |
| 26 | return new I18N($container['admin_options']); |
| 27 | }); |
| 28 | |
| 29 | $container['translate'] = $container->service(function(Container $container) { |
| 30 | return new Translate(); //phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.MissingArgText -- We're using namespaces, it's fine |
| 31 | }); |
| 32 | |
| 33 | $container['image'] = $container->service(function(Container $container) { |
| 34 | return new Image($container['admin_options']); |
| 35 | }); |
| 36 | |
| 37 | $container['themer'] = $container->service(function(Container $container) { |
| 38 | return new Themer(); |
| 39 | }); |
| 40 | |
| 41 | $container['output'] = $container->service(function(Container $container) { |
| 42 | return new Output( |
| 43 | $container['widget_options'], |
| 44 | $container['admin_options'], |
| 45 | $container['image'], |
| 46 | $container['translate'], |
| 47 | $container['themer'] |
| 48 | ); |
| 49 | }); |
| 50 | |
| 51 | $container['widget'] = $container->service(function(Container $container) { |
| 52 | return new Widget( |
| 53 | $container['widget_options'], |
| 54 | $container['admin_options'], |
| 55 | $container['output'], |
| 56 | $container['image'], |
| 57 | $container['translate'], |
| 58 | $container['themer'] |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | $container['block_widget'] = $container->service(function(Container $container) { |
| 63 | return new BlockWidget( |
| 64 | $container['admin_options'], |
| 65 | $container['output'], |
| 66 | $container['image'], |
| 67 | $container['translate'], |
| 68 | $container['themer'] |
| 69 | ); |
| 70 | }); |
| 71 | |
| 72 | $container['posts_endpoint'] = $container->service(function(Container $container) { |
| 73 | return new PostsEndpoint( |
| 74 | $container['admin_options'], |
| 75 | $container['translate'] |
| 76 | ); |
| 77 | }); |
| 78 | |
| 79 | $container['view_logger_endpoint'] = $container->service(function(Container $container) { |
| 80 | return new ViewLoggerEndpoint( |
| 81 | $container['admin_options'], |
| 82 | $container['translate'] |
| 83 | ); |
| 84 | }); |
| 85 | |
| 86 | $container['taxonomies_endpoint'] = $container->service(function(Container $container) { |
| 87 | return new TaxonomiesEndpoint( |
| 88 | $container['admin_options'], |
| 89 | $container['translate'] |
| 90 | ); |
| 91 | }); |
| 92 | |
| 93 | $container['themes_endpoint'] = $container->service(function(Container $container) { |
| 94 | return new ThemesEndpoint( |
| 95 | $container['admin_options'], |
| 96 | $container['translate'], |
| 97 | $container['themer'] |
| 98 | ); |
| 99 | }); |
| 100 | |
| 101 | $container['thumbnails_endpoint'] = $container->service(function(Container $container) { |
| 102 | return new ThumbnailsEndpoint( |
| 103 | $container['admin_options'], |
| 104 | $container['translate'] |
| 105 | ); |
| 106 | }); |
| 107 | |
| 108 | $container['widget_endpoint'] = $container->service(function(Container $container) { |
| 109 | return new WidgetEndpoint( |
| 110 | $container['admin_options'], |
| 111 | $container['translate'], |
| 112 | $container['output'] |
| 113 | ); |
| 114 | }); |
| 115 | |
| 116 | $container['rest'] = $container->service(function(Container $container) { |
| 117 | return new Controller( |
| 118 | $container['posts_endpoint'], |
| 119 | $container['view_logger_endpoint'], |
| 120 | $container['widget_endpoint'], |
| 121 | $container['themes_endpoint'], |
| 122 | $container['thumbnails_endpoint'], |
| 123 | $container['taxonomies_endpoint'] |
| 124 | ); |
| 125 | }); |
| 126 | |
| 127 | $container['admin'] = $container->service(function(Container $container) { |
| 128 | return new Admin( |
| 129 | $container['admin_options'], |
| 130 | $container['image'] |
| 131 | ); |
| 132 | }); |
| 133 | |
| 134 | $container['front'] = $container->service(function(Container $container) { |
| 135 | return new Front( |
| 136 | $container['admin_options'], |
| 137 | $container['translate'] |
| 138 | ); |
| 139 | }); |
| 140 | |
| 141 | $container['shortcode_loader'] = $container->service(function(Container $container) { |
| 142 | return new ShortcodeLoader( |
| 143 | $container['admin_options'], |
| 144 | $container['output'] |
| 145 | ); |
| 146 | }); |
| 147 | |
| 148 | $container['wpp'] = $container->service(function(Container $container) { |
| 149 | return new WordPressPopularPosts( |
| 150 | $container['i18n'], |
| 151 | $container['rest'], |
| 152 | $container['admin'], |
| 153 | $container['front'], |
| 154 | $container['widget'], |
| 155 | $container['block_widget'], |
| 156 | $container['shortcode_loader'] |
| 157 | ); |
| 158 | }); |
| 159 | } |
| 160 | } |
| 161 |