@@ -32,15 +32,16 @@ public function getModel(string $modelName): Model
32
32
throw new InvalidArgumentException ('Model name cannot be empty. ' );
33
33
}
34
34
35
- $ parsed = self :: parseModelName ($ modelName );
35
+ $ parsed = $ this -> parseModelName ($ modelName );
36
36
$ actualModelName = $ parsed ['name ' ];
37
+ $ catalogKey = $ parsed ['catalogKey ' ];
37
38
$ options = $ parsed ['options ' ];
38
39
39
- if (!isset ($ this ->models [$ actualModelName ])) {
40
+ if (!isset ($ this ->models [$ catalogKey ])) {
40
41
throw new ModelNotFoundException (\sprintf ('Model "%s" not found. ' , $ actualModelName ));
41
42
}
42
43
43
- $ modelConfig = $ this ->models [$ actualModelName ];
44
+ $ modelConfig = $ this ->models [$ catalogKey ];
44
45
$ modelClass = $ modelConfig ['class ' ];
45
46
46
47
if (!class_exists ($ modelClass )) {
@@ -65,12 +66,13 @@ public function getModels(): array
65
66
66
67
/**
67
68
* Extracts model name and options from a model name string that may contain query parameters.
69
+ * Also resolves size variants (e.g., "model:23b") to their base model for catalog lookup.
68
70
*
69
71
* @param string $modelName The model name, potentially with query parameters (e.g., "model-name?param=value&other=123")
70
72
*
71
- * @return array{name: string, options: array<string, mixed>} An array containing the model name and parsed options
73
+ * @return array{name: string, catalogKey: string, options: array<string, mixed>} An array containing the model name, catalog lookup key, and parsed options
72
74
*/
73
- protected static function parseModelName (string $ modelName ): array
75
+ protected function parseModelName (string $ modelName ): array
74
76
{
75
77
$ options = [];
76
78
$ actualModelName = $ modelName ;
@@ -87,8 +89,18 @@ protected static function parseModelName(string $modelName): array
87
89
$ options = self ::convertNumericStrings ($ options );
88
90
}
89
91
92
+ // Determine catalog key: try exact match first, then fall back to base model
93
+ $ catalogKey = $ actualModelName ;
94
+ if (!isset ($ this ->models [$ actualModelName ]) && str_contains ($ actualModelName , ': ' )) {
95
+ $ baseModelName = explode (': ' , $ actualModelName , 2 )[0 ];
96
+ if (isset ($ this ->models [$ baseModelName ])) {
97
+ $ catalogKey = $ baseModelName ;
98
+ }
99
+ }
100
+
90
101
return [
91
102
'name ' => $ actualModelName ,
103
+ 'catalogKey ' => $ catalogKey ,
92
104
'options ' => $ options ,
93
105
];
94
106
}
0 commit comments