PluginProbe
Auto Alt Text / 2.7.0
Auto Alt Text v2.7.0
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / src / App / Core / PluginBootstrap.php

PluginBootstrap.php in Auto Alt Text 2.7.0, at src/App/Core/PluginBootstrap.php

117 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AATXT\App\Core;
4
5 use AATXT\App\Admin\BulkActions\BulkActionHandler;
6 use AATXT\App\Admin\BulkActions\GenerateAltTextBulkAction;
7 use AATXT\App\Admin\MediaLibrary;
8 use AATXT\App\Infrastructure\Database\ErrorLogSchema;
9 use AATXT\App\Services\AltTextService;
10 use DI\Container as DIContainer;
11
12 /**
13 * Bootstrap class for the Auto Alt Text plugin.
14 *
15 * This class orchestrates the plugin initialization by:
16 * - Setting up the dependency injection container
17 * - Registering bulk actions
18 * - Initializing the hooks registrar
19 *
20 * Replaces the Singleton pattern in the old Setup class.
21 */
22 final class PluginBootstrap
23 {
24 /**
25 * Dependency injection container
26 *
27 * @var DIContainer
28 */
29 private $container;
30
31 /**
32 * Path to the main plugin file
33 *
34 * @var string
35 */
36 private $pluginFile;
37
38 /**
39 * Constructor
40 *
41 * @param DIContainer $container The DI container
42 * @param string $pluginFile Path to the main plugin file
43 */
44 public function __construct(DIContainer $container, string $pluginFile)
45 {
46 $this->container = $container;
47 $this->pluginFile = $pluginFile;
48 }
49
50 /**
51 * Boot the plugin.
52 *
53 * Initializes all plugin components and registers WordPress hooks.
54 *
55 * @return void
56 */
57 public function boot(): void
58 {
59 // Get services from container
60 $altTextService = $this->container->get(AltTextService::class);
61 $mediaLibrary = $this->container->get(MediaLibrary::class);
62 $schema = $this->container->get(ErrorLogSchema::class);
63
64 // Create plugin lifecycle handler
65 $lifecycle = new PluginLifecycle($schema);
66
67 // Create and configure bulk action handler
68 $bulkActionHandler = $this->createBulkActionHandler($altTextService);
69
70 // Create hooks registrar and register all hooks
71 $hooksRegistrar = new HooksRegistrar(
72 $altTextService,
73 $bulkActionHandler,
74 $lifecycle,
75 $mediaLibrary,
76 $this->pluginFile
77 );
78
79 $hooksRegistrar->register();
80 }
81
82 /**
83 * Create and configure the bulk action handler.
84 *
85 * @param AltTextService $altTextService The alt text service
86 * @return BulkActionHandler Configured bulk action handler
87 */
88 private function createBulkActionHandler(AltTextService $altTextService): BulkActionHandler
89 {
90 $handler = new BulkActionHandler();
91
92 // Register the generate alt text bulk action
93 $generateAltTextAction = new GenerateAltTextBulkAction($altTextService);
94 $handler->register($generateAltTextAction);
95
96 return $handler;
97 }
98
99 /**
100 * Static factory method for easy plugin initialization.
101 *
102 * Usage in main plugin file:
103 * ```php
104 * PluginBootstrap::init(__FILE__);
105 * ```
106 *
107 * @param string $pluginFile Path to the main plugin file
108 * @return void
109 */
110 public static function init(string $pluginFile): void
111 {
112 $container = Container::make();
113 $bootstrap = new self($container, $pluginFile);
114 $bootstrap->boot();
115 }
116 }
117