PluginProbe
Auto Alt Text / 2.8.2
Auto Alt Text v2.8.2
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.8.2, at src/App/Core/PluginBootstrap.php

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