@@ -46,21 +46,44 @@ protected function listBundles($output)
46
46
protected function findExtension ($ name )
47
47
{
48
48
$ bundles = $ this ->initializeBundles ();
49
+ $ minScore = INF ;
50
+
49
51
foreach ($ bundles as $ bundle ) {
52
+ $ distance = levenshtein ($ name , $ bundle ->getName ());
53
+
54
+ if ($ distance < $ minScore ) {
55
+ $ guess = $ bundle ->getName ();
56
+ $ minScore = $ distance ;
57
+ }
58
+
50
59
if ($ name === $ bundle ->getName ()) {
51
60
return $ bundle ->getContainerExtension ();
52
61
}
53
62
54
63
$ extension = $ bundle ->getContainerExtension ();
55
- if ($ extension && $ name === $ extension ->getAlias ()) {
56
- return $ extension ;
64
+
65
+ if ($ extension ) {
66
+ if ($ name === $ extension ->getAlias ()) {
67
+ return $ extension ;
68
+ }
69
+
70
+ $ distance = levenshtein ($ name , $ extension ->getAlias ());
71
+
72
+ if ($ distance < $ minScore ) {
73
+ $ guess = $ extension ->getAlias ();
74
+ $ minScore = $ distance ;
75
+ }
57
76
}
58
77
}
59
78
60
79
if ('Bundle ' !== substr ($ name , -6 )) {
61
- $ message = sprintf ('No extensions with configuration available for "%s" ' , $ name );
80
+ $ message = sprintf ('No extensions with configuration available for "%s". ' , $ name );
62
81
} else {
63
- $ message = sprintf ('No extension with alias "%s" is enabled ' , $ name );
82
+ $ message = sprintf ('No extension with alias "%s" is enabled. ' , $ name );
83
+ }
84
+
85
+ if (isset ($ guess ) && $ minScore < 3 ) {
86
+ $ message .= sprintf ("\n\nDid you mean \"%s \"? " , $ guess );
64
87
}
65
88
66
89
throw new \LogicException ($ message );
0 commit comments