2525 * instantiation checks.
2626 *
2727 * @method static BaseConfig|null config(...$arguments)
28- * @method static Model|null models(string $name , array $options = [], ?ConnectionInterface &$conn = null)
28+ * @method static Model|null models(string $alias , array $options = [], ?ConnectionInterface &$conn = null)
2929 */
3030class Factories
3131{
@@ -84,19 +84,19 @@ class Factories
8484 * Define the class to load. You can *override* the concrete class.
8585 *
8686 * @param string $component Lowercase, plural component name
87- * @param string $name Class alias. See the $aliases property.
87+ * @param string $alias Class alias. See the $aliases property.
8888 * @param string $classname FQCN to load
8989 * @phpstan-param class-string $classname FQCN to load
9090 */
91- public static function define (string $ component , string $ name , string $ classname ): void
91+ public static function define (string $ component , string $ alias , string $ classname ): void
9292 {
93- if (isset (self ::$ aliases [$ component ][$ name ])) {
94- if (self ::$ aliases [$ component ][$ name ] === $ classname ) {
93+ if (isset (self ::$ aliases [$ component ][$ alias ])) {
94+ if (self ::$ aliases [$ component ][$ alias ] === $ classname ) {
9595 return ;
9696 }
9797
9898 throw new InvalidArgumentException (
99- 'Already defined in Factories: ' . $ component . ' ' . $ name . ' -> ' . self ::$ aliases [$ component ][$ name ]
99+ 'Already defined in Factories: ' . $ component . ' ' . $ alias . ' -> ' . self ::$ aliases [$ component ][$ alias ]
100100 );
101101 }
102102
@@ -108,7 +108,7 @@ public static function define(string $component, string $name, string $classname
108108 // Otherwise, getOptions() will reset the component.
109109 self ::getOptions ($ component );
110110
111- self ::$ aliases [$ component ][$ name ] = $ classname ;
111+ self ::$ aliases [$ component ][$ alias ] = $ classname ;
112112 }
113113
114114 /**
@@ -120,29 +120,29 @@ public static function define(string $component, string $name, string $classname
120120 public static function __callStatic (string $ component , array $ arguments )
121121 {
122122 // First argument is the class alias, second is options
123- $ name = trim (array_shift ($ arguments ), '\\ ' );
123+ $ alias = trim (array_shift ($ arguments ), '\\ ' );
124124 $ options = array_shift ($ arguments ) ?? [];
125125
126126 // Determine the component-specific options
127127 $ options = array_merge (self ::getOptions (strtolower ($ component )), $ options );
128128
129129 if (! $ options ['getShared ' ]) {
130- if (isset (self ::$ aliases [$ component ][$ name ])) {
131- $ class = self ::$ aliases [$ component ][$ name ];
130+ if (isset (self ::$ aliases [$ component ][$ alias ])) {
131+ $ class = self ::$ aliases [$ component ][$ alias ];
132132
133133 return new $ class (...$ arguments );
134134 }
135135
136- if ($ class = self ::locateClass ($ options , $ name )) {
136+ if ($ class = self ::locateClass ($ options , $ alias )) {
137137 return new $ class (...$ arguments );
138138 }
139139
140140 return null ;
141141 }
142142
143143 // Check for an existing instance
144- if (isset (self ::$ aliases [$ options ['component ' ]][$ name ])) {
145- $ class = self ::$ aliases [$ options ['component ' ]][$ name ];
144+ if (isset (self ::$ aliases [$ options ['component ' ]][$ alias ])) {
145+ $ class = self ::$ aliases [$ options ['component ' ]][$ alias ];
146146
147147 // Need to verify if the shared instance matches the request
148148 if (self ::verifyInstanceOf ($ options , $ class )) {
@@ -158,7 +158,7 @@ public static function __callStatic(string $component, array $arguments)
158158
159159 // Check for an existing Config instance with basename.
160160 if (self ::isConfig ($ options ['component ' ])) {
161- $ basename = self ::getBasename ($ name );
161+ $ basename = self ::getBasename ($ alias );
162162
163163 if (isset (self ::$ aliases [$ options ['component ' ]][$ basename ])) {
164164 $ class = self ::$ aliases [$ options ['component ' ]][$ basename ];
@@ -176,12 +176,12 @@ public static function __callStatic(string $component, array $arguments)
176176 }
177177
178178 // Try to locate the class
179- if (! $ class = self ::locateClass ($ options , $ name )) {
179+ if (! $ class = self ::locateClass ($ options , $ alias )) {
180180 return null ;
181181 }
182182
183183 self ::$ instances [$ options ['component ' ]][$ class ] = new $ class (...$ arguments );
184- self ::$ aliases [$ options ['component ' ]][$ name ] = $ class ;
184+ self ::$ aliases [$ options ['component ' ]][$ alias ] = $ class ;
185185
186186 // If a short classname is specified, also register FQCN to share the instance.
187187 if (! isset (self ::$ aliases [$ options ['component ' ]][$ class ])) {
@@ -205,53 +205,53 @@ private static function isConfig(string $component): bool
205205 * Finds a component class
206206 *
207207 * @param array $options The array of component-specific directives
208- * @param string $name Class alias. See the $aliases property.
208+ * @param string $alias Class alias. See the $aliases property.
209209 */
210- protected static function locateClass (array $ options , string $ name ): ?string
210+ protected static function locateClass (array $ options , string $ alias ): ?string
211211 {
212212 // Check for low-hanging fruit
213213 if (
214- class_exists ($ name , false )
215- && self ::verifyPreferApp ($ options , $ name )
216- && self ::verifyInstanceOf ($ options , $ name )
214+ class_exists ($ alias , false )
215+ && self ::verifyPreferApp ($ options , $ alias )
216+ && self ::verifyInstanceOf ($ options , $ alias )
217217 ) {
218- return $ name ;
218+ return $ alias ;
219219 }
220220
221221 // Determine the relative class names we need
222- $ basename = self ::getBasename ($ name );
222+ $ basename = self ::getBasename ($ alias );
223223 $ appname = self ::isConfig ($ options ['component ' ])
224224 ? 'Config \\' . $ basename
225225 : rtrim (APP_NAMESPACE , '\\' ) . '\\' . $ options ['path ' ] . '\\' . $ basename ;
226226
227227 // If an App version was requested then see if it verifies
228228 if (
229229 // preferApp is used only for no namespace class.
230- strpos ($ name , '\\' ) === false
230+ strpos ($ alias , '\\' ) === false
231231 && $ options ['preferApp ' ] && class_exists ($ appname )
232- && self ::verifyInstanceOf ($ options , $ name )
232+ && self ::verifyInstanceOf ($ options , $ alias )
233233 ) {
234234 return $ appname ;
235235 }
236236
237237 // If we have ruled out an App version and the class exists then try it
238- if (class_exists ($ name ) && self ::verifyInstanceOf ($ options , $ name )) {
239- return $ name ;
238+ if (class_exists ($ alias ) && self ::verifyInstanceOf ($ options , $ alias )) {
239+ return $ alias ;
240240 }
241241
242242 // Have to do this the hard way...
243243 $ locator = Services::locator ();
244244
245245 // Check if the class was namespaced
246- if (strpos ($ name , '\\' ) !== false ) {
247- if (! $ file = $ locator ->locateFile ($ name , $ options ['path ' ])) {
246+ if (strpos ($ alias , '\\' ) !== false ) {
247+ if (! $ file = $ locator ->locateFile ($ alias , $ options ['path ' ])) {
248248 return null ;
249249 }
250250 $ files = [$ file ];
251251 }
252252 // No namespace? Search for it
253253 // Check all namespaces, prioritizing App and modules
254- elseif (! $ files = $ locator ->search ($ options ['path ' ] . DIRECTORY_SEPARATOR . $ name )) {
254+ elseif (! $ files = $ locator ->search ($ options ['path ' ] . DIRECTORY_SEPARATOR . $ alias )) {
255255 return null ;
256256 }
257257
@@ -271,9 +271,9 @@ class_exists($name, false)
271271 * Verifies that a class & config satisfy the "preferApp" option
272272 *
273273 * @param array $options The array of component-specific directives
274- * @param string $name Class alias. See the $aliases property.
274+ * @param string $alias Class alias. See the $aliases property.
275275 */
276- protected static function verifyPreferApp (array $ options , string $ name ): bool
276+ protected static function verifyPreferApp (array $ options , string $ alias ): bool
277277 {
278278 // Anything without that restriction passes
279279 if (! $ options ['preferApp ' ]) {
@@ -282,26 +282,26 @@ protected static function verifyPreferApp(array $options, string $name): bool
282282
283283 // Special case for Config since its App namespace is actually \Config
284284 if (self ::isConfig ($ options ['component ' ])) {
285- return strpos ($ name , 'Config ' ) === 0 ;
285+ return strpos ($ alias , 'Config ' ) === 0 ;
286286 }
287287
288- return strpos ($ name , APP_NAMESPACE ) === 0 ;
288+ return strpos ($ alias , APP_NAMESPACE ) === 0 ;
289289 }
290290
291291 /**
292292 * Verifies that a class & config satisfy the "instanceOf" option
293293 *
294294 * @param array $options The array of component-specific directives
295- * @param string $name Class alias. See the $aliases property.
295+ * @param string $alias Class alias. See the $aliases property.
296296 */
297- protected static function verifyInstanceOf (array $ options , string $ name ): bool
297+ protected static function verifyInstanceOf (array $ options , string $ alias ): bool
298298 {
299299 // Anything without that restriction passes
300300 if (! $ options ['instanceOf ' ]) {
301301 return true ;
302302 }
303303
304- return is_a ($ name , $ options ['instanceOf ' ], true );
304+ return is_a ($ alias , $ options ['instanceOf ' ], true );
305305 }
306306
307307 /**
@@ -388,24 +388,24 @@ public static function reset(?string $component = null)
388388 * Helper method for injecting mock instances
389389 *
390390 * @param string $component Lowercase, plural component name
391- * @param string $name Class alias. See the $aliases property.
391+ * @param string $alias Class alias. See the $aliases property.
392392 *
393393 * @internal For testing only
394394 */
395- public static function injectMock (string $ component , string $ name , object $ instance )
395+ public static function injectMock (string $ component , string $ alias , object $ instance )
396396 {
397397 // Force a configuration to exist for this component
398398 $ component = strtolower ($ component );
399399 self ::getOptions ($ component );
400400
401401 $ class = get_class ($ instance );
402- $ basename = self ::getBasename ($ name );
402+ $ basename = self ::getBasename ($ alias );
403403
404404 self ::$ instances [$ component ][$ class ] = $ instance ;
405- self ::$ aliases [$ component ][$ name ] = $ class ;
405+ self ::$ aliases [$ component ][$ alias ] = $ class ;
406406
407407 if (self ::isConfig ($ component )) {
408- if ($ name !== $ basename ) {
408+ if ($ alias !== $ basename ) {
409409 self ::$ aliases [$ component ][$ basename ] = $ class ;
410410 } else {
411411 self ::$ aliases [$ component ]['Config \\' . $ basename ] = $ class ;
@@ -418,13 +418,13 @@ public static function injectMock(string $component, string $name, object $insta
418418 *
419419 * @internal For testing only
420420 */
421- public static function getBasename (string $ name ): string
421+ public static function getBasename (string $ alias ): string
422422 {
423423 // Determine the basename
424- if ($ basename = strrchr ($ name , '\\' )) {
424+ if ($ basename = strrchr ($ alias , '\\' )) {
425425 return substr ($ basename , 1 );
426426 }
427427
428- return $ name ;
428+ return $ alias ;
429429 }
430430}
0 commit comments