PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
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 4.3.0, at includes/bootstrap/DataServiceRegistration.php

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