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 / database / DataAccessDependencies.php

DataAccessDependencies.php in 404 Solution 4.3.0, at includes/database/DataAccessDependencies.php

126 lines 4.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 * Explicit composition input for the DataAccess compatibility facade.
9 *
10 * DataAccess still owns the facade graph, but callers must name collaborator
11 * overrides by responsibility instead of threading nullable positional values.
12 */
13 class ABJ_404_Solution_DataAccessDependencies {
14
15 /** @var array<string, bool> */
16 private const KNOWN_KEYS = array(
17 'functions' => true,
18 'logging' => true,
19 'dbCore' => true,
20 'contentRepo' => true,
21 'redirectsRepo' => true,
22 'retentionService' => true,
23 'logsRepo' => true,
24 'statsRepo' => true,
25 'viewReadService' => true,
26 );
27
28 /** @var array<string, mixed> */
29 private $dependencies = array();
30
31 /**
32 * @param array<string, mixed> $dependencies Named collaborator overrides.
33 * @throws InvalidArgumentException when an unknown dependency name is supplied.
34 */
35 public function __construct(array $dependencies = array()) {
36 foreach ($dependencies as $name => $dependency) {
37 if (!isset(self::KNOWN_KEYS[$name])) {
38 throw new InvalidArgumentException('Unknown DataAccess dependency: ' . $name);
39 }
40 $this->dependencies[$name] = $dependency;
41 }
42 }
43
44 /** @return ABJ_404_Solution_Functions|null */
45 public function functions(): ?ABJ_404_Solution_Functions {
46 $value = $this->get('functions');
47 return $value instanceof ABJ_404_Solution_Functions ? $value : null;
48 }
49
50 /**
51 * Return the logging dependency. Accepts the production Logging class
52 * and also duck-typed test spies that expose the same method surface
53 * (debugMessage / infoMessage / warn / errorMessage). Returning the
54 * raw spy lets DAO components hold it as $this->logger and dispatch
55 * calls through it; without this, a spy is silently dropped and the
56 * production singleton is used instead, so level-discipline assertions
57 * see no captured warn/error output (broken test-as-mirror feedback).
58 *
59 * The widened return type lets the strict instanceof check live in one
60 * place (DataAccess::resolveLogger) instead of being duplicated here
61 * and there with adapter wrappers that the mock-lint blocks.
62 *
63 * @return ABJ_404_Solution_Logging|object|null
64 */
65 public function logging() {
66 $value = $this->get('logging');
67 if ($value instanceof ABJ_404_Solution_Logging) {
68 return $value;
69 }
70 if (is_object($value) && method_exists($value, 'warn') && method_exists($value, 'errorMessage')) {
71 return $value;
72 }
73 return null;
74 }
75
76 /** @return ABJ_404_Solution_DatabaseCore|null */
77 public function dbCore(): ?ABJ_404_Solution_DatabaseCore {
78 $value = $this->get('dbCore');
79 return $value instanceof ABJ_404_Solution_DatabaseCore ? $value : null;
80 }
81
82 /** @return ABJ_404_Solution_ContentRepository|null */
83 public function contentRepo(): ?ABJ_404_Solution_ContentRepository {
84 $value = $this->get('contentRepo');
85 return $value instanceof ABJ_404_Solution_ContentRepository ? $value : null;
86 }
87
88 /** @return ABJ_404_Solution_RedirectsRepository|null */
89 public function redirectsRepo(): ?ABJ_404_Solution_RedirectsRepository {
90 $value = $this->get('redirectsRepo');
91 return $value instanceof ABJ_404_Solution_RedirectsRepository ? $value : null;
92 }
93
94 /** @return ABJ_404_Solution_RedirectsRetentionService|null */
95 public function retentionService(): ?ABJ_404_Solution_RedirectsRetentionService {
96 $value = $this->get('retentionService');
97 return $value instanceof ABJ_404_Solution_RedirectsRetentionService ? $value : null;
98 }
99
100 /** @return ABJ_404_Solution_LogsRepository|null */
101 public function logsRepo(): ?ABJ_404_Solution_LogsRepository {
102 $value = $this->get('logsRepo');
103 return $value instanceof ABJ_404_Solution_LogsRepository ? $value : null;
104 }
105
106 /** @return ABJ_404_Solution_StatsRepository|null */
107 public function statsRepo(): ?ABJ_404_Solution_StatsRepository {
108 $value = $this->get('statsRepo');
109 return $value instanceof ABJ_404_Solution_StatsRepository ? $value : null;
110 }
111
112 /** @return ABJ_404_Solution_ViewReadService|null */
113 public function viewReadService(): ?ABJ_404_Solution_ViewReadService {
114 $value = $this->get('viewReadService');
115 return $value instanceof ABJ_404_Solution_ViewReadService ? $value : null;
116 }
117
118 /**
119 * @param string $name
120 * @return mixed|null
121 */
122 private function get(string $name) {
123 return array_key_exists($name, $this->dependencies) ? $this->dependencies[$name] : null;
124 }
125 }
126