42
42
/**
43
43
* Class Config
44
44
*
45
- * @package CodeIgniter\Config
45
+ * @deprecated Use CodeIgniter\Config\Factory::config()
46
46
*/
47
47
class Config
48
48
{
49
- /**
50
- * Cache for instance of any configurations that
51
- * have been requested as "shared" instance.
52
- *
53
- * @var array
54
- */
55
- static private $ instances = [];
56
-
57
- //--------------------------------------------------------------------
58
-
59
49
/**
60
50
* Create new configuration instances or return
61
51
* a shared instance
@@ -67,95 +57,25 @@ class Config
67
57
*/
68
58
public static function get (string $ name , bool $ getShared = true )
69
59
{
70
- $ class = $ name ;
71
- if (($ pos = strrpos ($ name , '\\' )) !== false )
72
- {
73
- $ class = substr ($ name , $ pos + 1 );
74
- }
75
-
76
- if (! $ getShared )
77
- {
78
- return self ::createClass ($ name );
79
- }
80
-
81
- if (! isset ( self ::$ instances [$ class ] ))
82
- {
83
- self ::$ instances [$ class ] = self ::createClass ($ name );
84
- }
85
- return self ::$ instances [$ class ];
60
+ return Factory::config ($ name , $ getShared );
86
61
}
87
62
88
- //--------------------------------------------------------------------
89
-
90
63
/**
91
64
* Helper method for injecting mock instances while testing.
92
65
*
93
- * @param string $class
66
+ * @param string $name
94
67
* @param object $instance
95
68
*/
96
- public static function injectMock (string $ class , $ instance )
69
+ public static function injectMock (string $ name , $ instance )
97
70
{
98
- self :: $ instances [ $ class ] = $ instance ;
71
+ Factory:: injectMock ( ' config ' , $ name , $ instance) ;
99
72
}
100
73
101
- //--------------------------------------------------------------------
102
-
103
74
/**
104
- * Resets the instances array
75
+ * Resets the static arrays
105
76
*/
106
77
public static function reset ()
107
78
{
108
- static ::$ instances = [];
109
- }
110
-
111
- //--------------------------------------------------------------------
112
-
113
- /**
114
- * Find configuration class and create instance
115
- *
116
- * @param string $name Classname
117
- *
118
- * @return mixed|null
119
- */
120
- private static function createClass (string $ name )
121
- {
122
- if (class_exists ($ name ))
123
- {
124
- return new $ name ();
125
- }
126
-
127
- $ locator = Services::locator ();
128
- $ file = $ locator ->locateFile ($ name , 'Config ' );
129
-
130
- if (empty ($ file ))
131
- {
132
- // No file found - check if the class was namespaced
133
- if (strpos ($ name , '\\' ) !== false )
134
- {
135
- // Class was namespaced and locateFile couldn't find it
136
- return null ;
137
- }
138
-
139
- // Check all namespaces
140
- $ files = $ locator ->search ('Config/ ' . $ name );
141
- if (empty ($ files ))
142
- {
143
- return null ;
144
- }
145
-
146
- // Get the first match (prioritizes user and framework)
147
- $ file = reset ($ files );
148
- }
149
-
150
- $ name = $ locator ->getClassname ($ file );
151
-
152
- if (empty ($ name ))
153
- {
154
- return null ;
155
- }
156
-
157
- return new $ name ();
79
+ Factory::reset ('config ' );
158
80
}
159
-
160
- //--------------------------------------------------------------------
161
81
}
0 commit comments