From 3c0b0ae84d0eb792c87dc50ae1855a98d9f16807 Mon Sep 17 00:00:00 2001 From: Stepan Anchugov Date: Fri, 22 Jan 2016 03:51:50 +0500 Subject: [PATCH] Add Levenshtein suggesters to AbstractConfigCommand --- .../Command/AbstractConfigCommand.php | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index 23a446017909f..f2e763f4eebfe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -46,21 +46,44 @@ protected function listBundles($output) protected function findExtension($name) { $bundles = $this->initializeBundles(); + $minScore = INF; + foreach ($bundles as $bundle) { if ($name === $bundle->getName()) { return $bundle->getContainerExtension(); } + $distance = levenshtein($name, $bundle->getName()); + + if ($distance < $minScore) { + $guess = $bundle->getName(); + $minScore = $distance; + } + $extension = $bundle->getContainerExtension(); - if ($extension && $name === $extension->getAlias()) { - return $extension; + + if ($extension) { + if ($name === $extension->getAlias()) { + return $extension; + } + + $distance = levenshtein($name, $extension->getAlias()); + + if ($distance < $minScore) { + $guess = $extension->getAlias(); + $minScore = $distance; + } } } if ('Bundle' !== substr($name, -6)) { - $message = sprintf('No extensions with configuration available for "%s"', $name); + $message = sprintf('No extensions with configuration available for "%s".', $name); } else { - $message = sprintf('No extension with alias "%s" is enabled', $name); + $message = sprintf('No extension with alias "%s" is enabled.', $name); + } + + if (isset($guess) && $minScore < 3) { + $message .= sprintf("\n\nDid you mean \"%s\"?", $guess); } throw new \LogicException($message); 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