@@ -101,22 +101,13 @@ public function clearCache(): bool
101
101
* Check if theme with given name exists.
102
102
*
103
103
* @param string $name
104
+ * @param string $vendor
104
105
*
105
106
* @return boolean
106
107
*/
107
108
public function has (string $ name = null )
108
109
{
109
- return !is_null ($ this ->themes ->first (function ($ theme ) use ($ name ) {
110
- // normalize module name
111
- $ name = str_replace (['-theme ' , 'theme- ' ], '' , $ name );
112
- // Check if $name contains vendor
113
- if (strpos ($ name , '/ ' ) !== false ) {
114
- return Str::lower ($ theme ->getName ()) === Str::lower (substr ($ name , $ pos + 1 , strlen ($ name )));
115
- ;
116
- } else {
117
- return $ theme ->getLowerName () === Str::lower ($ name );
118
- }
119
- }));
110
+ return !is_null ($ this ->findByName ($ name ));
120
111
}
121
112
122
113
/**
@@ -131,17 +122,7 @@ public function get(string $name = null)
131
122
if (is_null ($ name )) {
132
123
return $ this ->themes ;
133
124
} else {
134
- return $ this ->themes ->first (function ($ theme ) use ($ name ) {
135
- // normalize module name
136
- $ name = str_replace (['-theme ' , 'theme- ' ], '' , $ name );
137
- // Check if $name contains vendor
138
- if (strpos ($ name , '/ ' ) !== false ) {
139
- return Str::lower ($ theme ->getName ()) === Str::lower (substr ($ name , $ pos + 1 , strlen ($ name )));
140
- ;
141
- } else {
142
- return $ theme ->getLowerName () === Str::lower ($ name );
143
- }
144
- });
125
+ return $ this ->findByName ($ name );
145
126
}
146
127
}
147
128
@@ -373,6 +354,40 @@ private function htmlAttributes($attributes): string
373
354
}, array_keys ($ attributes )));
374
355
}
375
356
357
+ /**
358
+ * Find a theme by given name and vendor (optional)
359
+ * name can include vendor prefix (ie: hexadog/default)
360
+ * If no vendor provided and name not prefixed by vendor
361
+ * the first theme with given name is returned
362
+ *
363
+ * @param string $name
364
+ * @return void
365
+ */
366
+ protected function findByName (string $ name = null , string $ vendor = null )
367
+ {
368
+ if (is_null ($ name )) {
369
+ return null ;
370
+ }
371
+
372
+ return $ this ->themes ->first (function ($ theme ) use ($ name , $ vendor ) {
373
+ // normalize module name
374
+ $ name = str_replace (['-theme ' , 'theme- ' ], '' , $ name );
375
+ // Check if $name contains vendor
376
+ if (($ pos = strpos ($ name , '/ ' )) !== false ) {
377
+ $ vendor = substr ($ name , 0 , $ pos );
378
+ $ name = substr ($ name , $ pos + 1 , strlen ($ name ));
379
+
380
+ return Str::lower ($ theme ->getName ()) === Str::lower ($ name ) && $ theme ->getLowerVendor () === Str::lower ($ vendor );
381
+ } else {
382
+ if (is_null ($ vendor )) {
383
+ return $ theme ->getLowerName () === Str::lower ($ name );
384
+ } else {
385
+ return $ theme ->getLowerName () === Str::lower ($ name ) && $ theme ->getLowerVendor () === Str::lower ($ vendor );
386
+ }
387
+ }
388
+ });
389
+ }
390
+
376
391
/**
377
392
* Find all available themes.
378
393
*
0 commit comments