@@ -276,40 +276,41 @@ public function componentClass(string $component)
276
276
}
277
277
278
278
/**
279
- * Guess the class name for the given component.
279
+ * Find the class for the given component using the registered namespaces .
280
280
*
281
281
* @param string $component
282
- * @return string
282
+ * @return string|null
283
283
*/
284
- public function guessClassName (string $ component )
284
+ public function findClassByComponent (string $ component )
285
285
{
286
- $ namespace = Container::getInstance ()
287
- ->make (Application::class)
288
- ->getNamespace ();
286
+ $ segments = explode (':: ' , $ component );
289
287
290
- $ class = $ this -> formatClassName ( $ component ) ;
288
+ $ prefix = $ segments [ 0 ] ;
291
289
292
- return $ namespace .'View \\Components \\' .$ class ;
290
+ if (! isset ($ this ->namespaces [$ prefix ]) || ! isset ($ segments [1 ])) {
291
+ return ;
292
+ }
293
+
294
+ if (class_exists ($ class = $ this ->namespaces [$ prefix ].'\\' .$ this ->formatClassName ($ segments [1 ]))) {
295
+ return $ class ;
296
+ }
293
297
}
294
298
295
299
/**
296
- * Find the class for the given component.
300
+ * Guess the class name for the given component.
297
301
*
298
302
* @param string $component
299
- * @return string|null
303
+ * @return string
300
304
*/
301
- public function findClassByComponent (string $ component )
305
+ public function guessClassName (string $ component )
302
306
{
303
- $ pieces = explode (':: ' , $ component );
304
- $ prefix = $ pieces [0 ];
307
+ $ namespace = Container::getInstance ()
308
+ ->make (Application::class)
309
+ ->getNamespace ();
305
310
306
- if (! isset ($ this ->namespaces [$ prefix ]) || ! isset ($ pieces [1 ])) {
307
- return ;
308
- }
311
+ $ class = $ this ->formatClassName ($ component );
309
312
310
- if (class_exists ($ location = $ this ->namespaces [$ prefix ].'\\' .$ this ->formatClassName ($ pieces [1 ]))) {
311
- return $ location ;
312
- }
313
+ return $ namespace .'View \\Components \\' .$ class ;
313
314
}
314
315
315
316
/**
0 commit comments