| 1 |
<?php |
| 2 |
|
| 3 |
namespace AATXT\App\Core; |
| 4 |
|
| 5 |
use AATXT\App\Infrastructure\Database\ErrorLogSchema; |
| 6 |
|
| 7 |
/** |
| 8 |
* Handles plugin lifecycle events (activation/deactivation). |
| 9 |
* |
| 10 |
* This class follows the Single Responsibility Principle by handling |
| 11 |
* only lifecycle-related operations like database schema management. |
| 12 |
*/ |
| 13 |
final class PluginLifecycle |
| 14 |
{ |
| 15 |
/** |
| 16 |
* Database schema manager for error logs table |
| 17 |
* |
| 18 |
* @var ErrorLogSchema |
| 19 |
*/ |
| 20 |
private $schema; |
| 21 |
|
| 22 |
/** |
| 23 |
* Constructor |
| 24 |
* |
| 25 |
* @param ErrorLogSchema $schema Database schema manager |
| 26 |
*/ |
| 27 |
public function __construct(ErrorLogSchema $schema) |
| 28 |
{ |
| 29 |
$this->schema = $schema; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Handle plugin activation. |
| 34 |
* |
| 35 |
* Creates necessary database tables. |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function activate(): void |
| 40 |
{ |
| 41 |
$this->schema->create(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Handle plugin deactivation. |
| 46 |
* |
| 47 |
* Drops database tables created by the plugin. |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function deactivate(): void |
| 52 |
{ |
| 53 |
$this->schema->drop(); |
| 54 |
} |
| 55 |
} |
| 56 |
|