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

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

60 lines 2.6 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 * Resolves legacy class-name lookups against the service container.
9 */
10 class ABJ_404_Solution_LegacyInstanceResolver {
11
12 /**
13 * @param string $className The class name to get an instance of
14 * @return mixed The service instance
15 * @throws Exception when no service or singleton fallback can resolve the class
16 */
17 public static function resolve($className) {
18 $container = ABJ_404_Solution_ServiceContainer::getInstance();
19
20 // Map class names to service names.
21 $serviceMap = array(
22 'ABJ_404_Solution_Functions' => 'functions',
23 'ABJ_404_Solution_Logging' => 'logging',
24 'ABJ_404_Solution_DataAccess' => 'data_access',
25 'ABJ_404_Solution_PluginLogic' => 'plugin_logic',
26 'ABJ_404_Solution_View' => 'view',
27 'ABJ_404_Solution_SpellChecker' => 'spell_checker',
28 'ABJ_404_Solution_WordPress_Connector' => 'wordpress_connector',
29 // Error handler is static; no instance.
30 'ABJ_404_Solution_DatabaseUpgradesEtc' => 'database_upgrades',
31 'ABJ_404_Solution_PermalinkCache' => 'permalink_cache',
32 'ABJ_404_Solution_NGramFilter' => 'ngram_filter',
33 'ABJ_404_Solution_SlugChangeHandler' => 'slug_change_handler',
34 // PublishedPostsProvider is intentionally not a shared service; its
35 // getInstance() builds a fresh instance, so legacy resolution falls
36 // through to that below rather than a container lookup.
37 'ABJ_404_Solution_SynchronizationUtils' => 'sync_utils',
38 'ABJ_404_Solution_View_Suggestions' => 'view_suggestions',
39 'ABJ_404_Solution_ShortCode' => 'shortcode',
40 'ABJ_404_Solution_RequestContext' => 'request_context',
41 'ABJ_404_Solution_NotFoundResponseService' => 'not_found_response',
42 'ABJ_404_Solution_PreviousRequestCookieTracker' => 'previous_request_cookie_tracker',
43 'ABJ_404_Solution_RequestIgnoreNormalizer' => 'request_ignore_normalizer',
44 );
45
46 if (isset($serviceMap[$className])) {
47 return $container->get($serviceMap[$className]);
48 }
49
50 // Fallback to calling the class's getInstance() method.
51 if (method_exists($className, 'getInstance')) {
52 /** @var callable(): mixed $callback */
53 $callback = array($className, 'getInstance');
54 return call_user_func($callback);
55 }
56
57 throw new Exception("Cannot get instance of class: $className"); // allow-raw-error: pre-existing programmer assertion
58 }
59 }
60