| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Service Provider |
| 4 |
* |
| 5 |
* @package Forge12\DoubleOptIn\Providers |
| 6 |
* @since 4.2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Forge12\DoubleOptIn\Providers; |
| 10 |
|
| 11 |
use Forge12\DoubleOptIn\Container\Container; |
| 12 |
use Forge12\DoubleOptIn\Container\BootableProviderInterface; |
| 13 |
use Forge12\DoubleOptIn\Admin\AdminNoticeIncompleteForms; |
| 14 |
use Forge12\DoubleOptIn\Admin\AdminPageController; |
| 15 |
use Forge12\DoubleOptIn\Admin\AdminRestController; |
| 16 |
use Forge12\DoubleOptIn\Audit\AuditLogger; |
| 17 |
use Forge12\DoubleOptIn\FormSettings\FormSettingsService; |
| 18 |
use Forge12\DoubleOptIn\FormSettings\FormSettingsValidator; |
| 19 |
use Forge12\Shared\LoggerInterface; |
| 20 |
|
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Class AdminServiceProvider |
| 27 |
* |
| 28 |
* Registers admin REST API and audit services. |
| 29 |
*/ |
| 30 |
class AdminServiceProvider implements BootableProviderInterface { |
| 31 |
|
| 32 |
/** |
| 33 |
* {@inheritdoc} |
| 34 |
*/ |
| 35 |
public function register( Container $container ): void { |
| 36 |
// Register Admin REST Controller |
| 37 |
$container->singleton( |
| 38 |
AdminRestController::class, |
| 39 |
function ( Container $c ) { |
| 40 |
return new AdminRestController( |
| 41 |
$c->get( LoggerInterface::class ), |
| 42 |
$c->get( FormSettingsService::class ), |
| 43 |
$c->get( FormSettingsValidator::class ) |
| 44 |
); |
| 45 |
} |
| 46 |
); |
| 47 |
|
| 48 |
// Register Admin Page Controller (React SPA) |
| 49 |
$container->singleton( |
| 50 |
AdminPageController::class, |
| 51 |
function () { |
| 52 |
return new AdminPageController(); |
| 53 |
} |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritdoc} |
| 59 |
*/ |
| 60 |
public function boot( Container $container ): void { |
| 61 |
// Initialize Admin REST Controller |
| 62 |
$restController = $container->get( AdminRestController::class ); |
| 63 |
$restController->init(); |
| 64 |
|
| 65 |
// Initialize Admin Page Controller (React SPA) |
| 66 |
$pageController = $container->get( AdminPageController::class ); |
| 67 |
$pageController->init(); |
| 68 |
|
| 69 |
// Register audit log hooks |
| 70 |
AuditLogger::registerHooks(); |
| 71 |
|
| 72 |
// Render the completeness-sweep admin notice for any forms that |
| 73 |
// the MigrationFormCompletenessSweep auto-disabled at upgrade |
| 74 |
// time. Notice persists until dismissed (plan §2.4). |
| 75 |
( new AdminNoticeIncompleteForms() )->register(); |
| 76 |
} |
| 77 |
} |
| 78 |
|