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

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

103 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 redirect matching engines and the filterable engine list.
9 */
10 class ABJ_404_Solution_MatchingEngineServiceRegistration {
11
12 /**
13 * @param ABJ_404_Solution_ServiceContainer $container
14 * @return void
15 */
16 public static function register($container): void {
17 $container->set('old_permalink_structure_store', function($c) {
18 return new ABJ_404_Solution_OldPermalinkStructureStore();
19 });
20
21 $container->set('old_permalink_structure_resolver', function($c) {
22 return new ABJ_404_Solution_OldPermalinkStructureResolver(
23 $c->get('old_permalink_structure_store'),
24 $c->get('content_repository'),
25 $c->get('logging')
26 );
27 });
28
29 $container->set('engine_old_permalink_structure', function($c) {
30 return new ABJ_404_Solution_OldPermalinkStructureEngine(
31 $c->get('old_permalink_structure_resolver')
32 );
33 });
34
35 $container->set('engine_slug', function($c) {
36 return new ABJ_404_Solution_SlugMatchingEngine($c->get('spell_checker'));
37 });
38
39 $container->set('engine_url_fix', function($c) {
40 return new ABJ_404_Solution_UrlFixEngine(
41 $c->get('spell_checker'),
42 $c->get('functions'),
43 $c->get('logging')
44 );
45 });
46
47 $container->set('engine_title', function($c) {
48 return new ABJ_404_Solution_TitleMatchingEngine(
49 $c->get('content_repository'),
50 $c->get('functions'),
51 $c->get('logging')
52 );
53 });
54
55 $container->set('engine_category_tag', function($c) {
56 return new ABJ_404_Solution_CategoryTagMatchingEngine(
57 $c->get('content_repository'),
58 $c->get('functions'),
59 $c->get('logging'),
60 $c->get('term_candidate_source')
61 );
62 });
63
64 $container->set('engine_content', function($c) {
65 return new ABJ_404_Solution_ContentMatchingEngine(
66 $c->get('content_repository'),
67 $c->get('functions'),
68 $c->get('logging')
69 );
70 });
71
72 $container->set('engine_spelling', function($c) {
73 return new ABJ_404_Solution_SpellingMatchingEngine($c->get('spell_checker'));
74 });
75
76 $container->set('engine_archive_fallback', function($c) {
77 return new ABJ_404_Solution_ArchiveFallbackEngine(
78 $c->get('functions'),
79 $c->get('logging')
80 );
81 });
82
83 // Request-scoped carrier for matches the engines found and rejected for
84 // scoring under the auto-redirect threshold. Written by the engine side
85 // (SpellChecker), read by the captured-404 insert
86 // (NotFoundResponseService) so the Captured tab can show why a URL was
87 // not redirected. Shared instance: producer and consumer must see the
88 // same recorder within a request.
89 $container->set('near_miss_recorder', function($c) {
90 return new ABJ_404_Solution_NearMissRecorder();
91 });
92
93 $container->set('matching_engines', function($c) {
94 $engines = [$c->get('engine_old_permalink_structure'), $c->get('engine_slug'), $c->get('engine_url_fix'), $c->get('engine_title'), $c->get('engine_category_tag'), $c->get('engine_content'), $c->get('engine_spelling'), $c->get('engine_archive_fallback')];
95 if (function_exists('apply_filters')) {
96 $filtered = apply_filters('abj404_matching_engines', $engines);
97 $engines = is_array($filtered) ? $filtered : [];
98 }
99 return $engines;
100 });
101 }
102 }
103