PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.0
5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 3.1.0 All 34 releases
double-opt-in / src / Providers / AddonServiceProvider.php

AddonServiceProvider.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.5.0, at src/Providers/AddonServiceProvider.php

93 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Addon Service Provider
4 *
5 * Registers the AddonRegistry in the container and wires up the addon
6 * bootstrap lifecycle.
7 *
8 * @package Forge12\DoubleOptIn\Providers
9 * @since 4.3.0
10 */
11
12 namespace Forge12\DoubleOptIn\Providers;
13
14 use Forge12\DoubleOptIn\Addon\AddonRegistry;
15 use Forge12\DoubleOptIn\Container\BootableProviderInterface;
16 use Forge12\DoubleOptIn\Container\Container;
17 use Forge12\Shared\LoggerInterface;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Class AddonServiceProvider
25 *
26 * Lifecycle:
27 * 1. {@see register()} puts the AddonRegistry into the container.
28 * 2. {@see boot()} schedules the `f12_cf7_doubleoptin_register_addons`
29 * action for `plugins_loaded` priority 20. This is one priority step
30 * later than the core instantiation at priority 10, giving addon
31 * plugins that also hook at priority 10 time to load.
32 * 3. After addons register, the registry is booted so each addon's
33 * own {@see \Forge12\DoubleOptIn\Addon\AddonInterface::boot()} runs
34 * with the fully wired container.
35 */
36 class AddonServiceProvider implements BootableProviderInterface {
37
38 /**
39 * {@inheritdoc}
40 */
41 public function register( Container $container ): void {
42 $container->singleton(
43 AddonRegistry::class,
44 function () use ( $container ) {
45 $registry = AddonRegistry::getInstance();
46
47 if ( $container->has( LoggerInterface::class ) ) {
48 $registry->setLogger( $container->get( LoggerInterface::class ) );
49 }
50
51 return $registry;
52 }
53 );
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function boot( Container $container ): void {
60 $registry = $container->get( AddonRegistry::class );
61
62 /*
63 * Decoupling rationale: boot() itself runs during Container::boot(),
64 * which fires at plugins_loaded priority 10 while the main plugin is
65 * being instantiated. Addon plugins that hook on plugins_loaded:10
66 * may not have loaded yet, so we defer the registration window by
67 * one priority step. Late-registering addons after priority 20 will
68 * still be picked up by the register() method's late-boot path.
69 */
70 add_action(
71 'plugins_loaded',
72 function () use ( $registry, $container ) {
73 /**
74 * Fires once per request, giving addon plugins the opportunity
75 * to register themselves with the AddonRegistry.
76 *
77 * @since 4.3.0
78 *
79 * @param AddonRegistry $registry The addon registry.
80 * @param Container $container The core DI container, for
81 * addons that need it at
82 * registration time (rare —
83 * prefer AddonInterface::boot()).
84 */
85 do_action( 'f12_cf7_doubleoptin_register_addons', $registry, $container );
86
87 $registry->bootAll( $container );
88 },
89 20
90 );
91 }
92 }
93