PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / bootstrap / DomainServiceRegistration.php

DomainServiceRegistration.php in 404 Solution trunk, at includes/bootstrap/DomainServiceRegistration.php

97 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Registers plugin-domain services, option access, and admin access policy.
9 */
10 class ABJ_404_Solution_DomainServiceRegistration {
11
12 /**
13 * @param ABJ_404_Solution_ServiceContainer $container
14 * @return void
15 */
16 public static function register($container): void {
17 $container->set('plugin_logic', function($c) {
18 if (class_exists('ABJ_404_Solution_PluginLogic', false)) {
19 $peeked = ABJ_404_Solution_PluginLogic::peekInstance();
20 if ($peeked !== null) {
21 return $peeked;
22 }
23 }
24 // Use abj_service() for data_access and logging so a caller that
25 // installed a singleton override via reflection wins over the
26 // container's freshly-built default. The other deps remain
27 // container-resolved.
28 return new ABJ_404_Solution_PluginLogic(
29 $c->get('functions'),
30 abj_service('data_access'),
31 abj_service('logging'),
32 $c->get('stats_repository')
33 );
34 });
35
36 $container->set('request_ignore_normalizer', function($c) {
37 return new ABJ_404_Solution_RequestIgnoreNormalizer(
38 new ABJ_404_Solution_RequestIgnoreNormalizerDependencies(
39 $c->get('options_repository'),
40 $c->get('functions'),
41 $c->get('logging'),
42 $c->get('redirects_repository'),
43 $c->get('logs_repository'),
44 $c->get('not_found_response')
45 )
46 );
47 });
48
49 $container->set('version_upgrade', function($c) {
50 return new ABJ_404_Solution_PluginLogicVersionUpgrader(
51 $c->get('functions'),
52 $c->get('logging'),
53 $c->get('db_core')
54 );
55 });
56
57 $container->set('spell_checker', function($c) {
58 // Honor a test-installed singleton override (via reflection /
59 // setInstance) the same way the plugin_logic factory above does.
60 // Without this peek, abj_service('spell_checker') always builds a
61 // fresh real SpellChecker and silently ignores a swapped-in double,
62 // so handlers that resolve through the container never hit the test's
63 // findMatchingPosts seam.
64 if (class_exists('ABJ_404_Solution_SpellChecker', false)) {
65 $peeked = ABJ_404_Solution_SpellChecker::peekInstance();
66 if ($peeked !== null) {
67 return $peeked;
68 }
69 }
70 return new ABJ_404_Solution_SpellChecker(new ABJ_404_Solution_SpellCheckerDependencies(
71 $c->get('functions'), $c->get('plugin_logic'),
72 $c->get('content_repository'), $c->get('logging'), $c->get('permalink_cache'),
73 $c->get('ngram_filter'), $c->get('view_read_service')));
74 });
75
76 $container->set('options_repository', function($c) {
77 return new ABJ_404_Solution_PluginLogicOptionsResolver();
78 });
79
80 $container->set('logging_state_store', function($c) {
81 return new ABJ_404_Solution_LoggingStateStore($c->get('options_repository'));
82 });
83
84 $container->set('admin_access_policy', function($c) {
85 return new ABJ_404_Solution_PluginAdminAccessPolicy(
86 $c->get('options_repository'),
87 $c->get('functions'),
88 $c->get('logging')
89 );
90 });
91
92 $container->set('settings_mode_preference', function($c) {
93 return new ABJ_404_Solution_SettingsModePreference();
94 });
95 }
96 }
97