Skip to content

Commit a031489

Browse files
committed
Add Levenshtein suggesters to AbstractConfigCommand
1 parent 09f92ba commit a031489

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,44 @@ protected function listBundles($output)
4646
protected function findExtension($name)
4747
{
4848
$bundles = $this->initializeBundles();
49+
$minScore = INF;
50+
4951
foreach ($bundles as $bundle) {
52+
$distance = levenshtein($name, $bundle->getName());
53+
54+
if ($distance < $minScore) {
55+
$guess = $bundle->getName();
56+
$minScore = $distance;
57+
}
58+
5059
if ($name === $bundle->getName()) {
5160
return $bundle->getContainerExtension();
5261
}
5362

5463
$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+
}
5776
}
5877
}
5978

6079
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);
6281
} 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);
6487
}
6588

6689
throw new \LogicException($message);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy