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 / DataServiceRegistration.php

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

219 lines 8.9 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 persistence, view-data, upgrade, cache, and ngram data services.
9 */
10 class ABJ_404_Solution_DataServiceRegistration {
11
12 /**
13 * @param ABJ_404_Solution_ServiceContainer $container
14 * @return void
15 */
16 public static function register($container): void {
17 $container->set('db_core', function($c) {
18 return new ABJ_404_Solution_DatabaseCore(
19 $c->get('functions'),
20 $c->get('logging')
21 );
22 });
23
24 $daoModuleDeps = function($c) { return [$c->get('db_core'), $c->get('functions'), $c->get('logging')]; };
25 $container->set('content_repository', function($c) use ($daoModuleDeps) {
26 return new ABJ_404_Solution_ContentRepository(...$daoModuleDeps($c));
27 });
28 $container->set('redirects_repository', function($c) use ($daoModuleDeps) {
29 return new ABJ_404_Solution_RedirectsRepository(...$daoModuleDeps($c));
30 });
31 $container->set('redirects_retention_service', function($c) {
32 return new ABJ_404_Solution_RedirectsRetentionService(
33 $c->get('db_core'),
34 $c->get('redirects_repository'),
35 $c->get('functions'),
36 $c->get('logging')
37 );
38 });
39 $container->set('redirect_dead_destination_checker', function($c) {
40 return new ABJ_404_Solution_RedirectDeadDestinationChecker(
41 $c->get('db_core'),
42 $c->get('logging')
43 );
44 });
45 $container->set('logs_repository', function($c) {
46 $rollup = new ABJ_404_Solution_LogsHitsRollupService(
47 $c->get('db_core'),
48 $c->get('logging'),
49 $c->get('rebuild_health')
50 );
51 return new ABJ_404_Solution_LogsRepository(
52 $c->get('db_core'),
53 $c->get('functions'),
54 $c->get('logging'),
55 $c->get('rebuild_health'),
56 $rollup
57 );
58 });
59 $container->set('stats_repository', function($c) {
60 return new ABJ_404_Solution_StatsRepository(
61 $c->get('db_core'), $c->get('logs_repository'),
62 $c->get('functions'), $c->get('logging')
63 );
64 });
65 $container->set('internal_source_evidence_repository', function($c) {
66 return new ABJ_404_Solution_InternalSourceEvidenceRepository(
67 $c->get('db_core'),
68 $c->get('functions')
69 );
70 });
71 $container->set('plugin_update_metadata_repository', function($c) {
72 return new ABJ_404_Solution_PluginUpdateMetadataRepository(
73 $c->get('db_core'), $c->get('functions'), $c->get('logging')
74 );
75 });
76 $container->set('view_read_service', function($c) use ($daoModuleDeps) {
77 return self::createViewReadService($c, $daoModuleDeps);
78 });
79 $container->set('data_access', function($c) {
80 return new ABJ_404_Solution_DataAccess(new ABJ_404_Solution_DataAccessDependencies(array(
81 'functions' => $c->get('functions'),
82 'logging' => $c->get('logging'),
83 'dbCore' => $c->get('db_core'),
84 'contentRepo' => $c->get('content_repository'),
85 'redirectsRepo' => $c->get('redirects_repository'),
86 'retentionService' => $c->get('redirects_retention_service'),
87 'logsRepo' => $c->get('logs_repository'),
88 'statsRepo' => $c->get('stats_repository'),
89 'viewReadService' => $c->get('view_read_service'),
90 )));
91 });
92
93 $container->set('database_upgrades', function($c) {
94 $existing = ABJ_404_Solution_DatabaseUpgradesEtc::peekInstance();
95 if ($existing instanceof ABJ_404_Solution_DatabaseUpgradesEtc) {
96 return $existing;
97 }
98 $upgrades = new ABJ_404_Solution_DatabaseUpgradesEtc(
99 new ABJ_404_Solution_DatabaseUpgradesDependencies(array(
100 'dataAccess' => $c->get('data_access'),
101 'logging' => $c->get('logging'),
102 'functions' => $c->get('functions'),
103 'permalinkCache' => $c->get('permalink_cache'),
104 'syncUtils' => $c->get('sync_utils'),
105 'pluginLogic' => $c->get('plugin_logic'),
106 'ngramFilter' => $c->get('ngram_filter'),
107 'ngramExtractor' => $c->get('ngram_extractor'),
108 'ngramCacheRepository' => $c->get('ngram_cache_repository'),
109 'ngramCoveragePolicy' => $c->get('ngram_coverage_policy'),
110 'ngramRebuilder' => $c->get('ngram_rebuilder'),
111 ))
112 );
113 ABJ_404_Solution_DatabaseUpgradesEtc::setInstance($upgrades);
114 return $upgrades;
115 });
116
117 $container->set('permalink_cache', function($c) {
118 return new ABJ_404_Solution_PermalinkCache($c->get('content_repository'),
119 $c->get('logging'), $c->get('stats_repository'));
120 });
121
122 $container->set('ngram_extractor', function($c) {
123 return new ABJ_404_Solution_NGramExtractor($c->get('functions'), $c->get('logging'));
124 });
125
126 $container->set('ngram_similarity', function($c) {
127 return new ABJ_404_Solution_NGramSimilarity();
128 });
129
130 $container->set('ngram_coverage_policy', function($c) {
131 return new ABJ_404_Solution_NGramCoveragePolicy($c->get('db_core'));
132 });
133
134 $container->set('ngram_cache_repository', function($c) {
135 return new ABJ_404_Solution_NGramCacheRepository(
136 $c->get('db_core'),
137 $c->get('logging'),
138 $c->get('ngram_similarity'),
139 // Lazy resolver: the policy invalidation hook fires on write but the
140 // policy itself doesn't exist when the repo is constructed if both
141 // are wired in the same pass. Resolve on demand.
142 function() use ($c) { return $c->get('ngram_coverage_policy'); }
143 );
144 });
145
146 $container->set('ngram_usage_telemetry', function($c) {
147 return new ABJ_404_Solution_NGramUsageTelemetry();
148 });
149
150 $container->set('ngram_rebuilder', function($c) {
151 return new ABJ_404_Solution_NGramRebuilder(
152 new ABJ_404_Solution_NGramRebuilderDependencies(
153 $c->get('db_core'),
154 $c->get('logging'),
155 $c->get('functions'),
156 $c->get('ngram_extractor'),
157 $c->get('ngram_cache_repository'),
158 $c->get('ngram_coverage_policy')
159 )
160 );
161 });
162
163 $container->set('ngram_filter', function($c) {
164 return new ABJ_404_Solution_NGramFilter(
165 $c->get('db_core'),
166 $c->get('logging'),
167 $c->get('functions'),
168 $c->get('ngram_extractor'),
169 $c->get('ngram_similarity'),
170 $c->get('ngram_cache_repository'),
171 $c->get('ngram_coverage_policy'),
172 $c->get('ngram_usage_telemetry')
173 );
174 });
175
176 $container->set('published_terms_provider', function($c) {
177 return new ABJ_404_Solution_PublishedTermsProvider(
178 $c->get('db_core'),
179 $c->get('functions'),
180 $c->get('logging')
181 );
182 });
183
184 $container->set('term_ngram_coverage_policy', function($c) {
185 return new ABJ_404_Solution_TermNGramCoveragePolicy(
186 $c->get('ngram_filter'),
187 $c->get('content_repository'),
188 $c->get('logging')
189 );
190 });
191
192 $container->set('term_candidate_source', function($c) {
193 return new ABJ_404_Solution_TermCandidateSource(
194 $c->get('content_repository'),
195 $c->get('ngram_filter'),
196 $c->get('published_terms_provider'),
197 $c->get('term_ngram_coverage_policy')
198 );
199 });
200 }
201
202 /**
203 * @param ABJ_404_Solution_ServiceContainer $container
204 * @param callable $daoModuleDeps
205 * @return ABJ_404_Solution_ViewReadService
206 */
207 private static function createViewReadService($container, $daoModuleDeps) {
208 /** @var array{0: ABJ_404_Solution_DatabaseCore, 1: ABJ_404_Solution_Functions, 2: ABJ_404_Solution_Logging} $d */
209 $d = $daoModuleDeps($container);
210 /** @var ABJ_404_Solution_LogsRepository $logsRepository */
211 $logsRepository = $container->get('logs_repository');
212 /** @var ABJ_404_Solution_RedirectsRepository $redirectsRepository */
213 $redirectsRepository = $container->get('redirects_repository');
214 return new ABJ_404_Solution_ViewReadService(
215 $d[0], $logsRepository, $redirectsRepository, $d[1], $d[2]
216 );
217 }
218 }
219