|
62 | 62 | */
|
63 | 63 | class Application
|
64 | 64 | {
|
| 65 | + const SUGGESTED_PACKAGES = [ |
| 66 | + 'doctrine' => [ |
| 67 | + 'Doctrine ORM', |
| 68 | + 'symfony/orm-pack', |
| 69 | + ], |
| 70 | + 'generate' => [ |
| 71 | + 'SensioGeneratorBundle', |
| 72 | + 'sensio/generator-bundle', |
| 73 | + ], |
| 74 | + 'make' => [ |
| 75 | + 'MakerBundle', |
| 76 | + 'symfony/maker-bundle --dev', |
| 77 | + ], |
| 78 | + 'server' => [ |
| 79 | + 'Symfony Web Server', |
| 80 | + 'symfony/web-server-bundle --dev', |
| 81 | + ], |
| 82 | + ]; |
| 83 | + |
65 | 84 | private $commands = array();
|
66 | 85 | private $wantHelps = false;
|
67 | 86 | private $runningCommand;
|
@@ -563,6 +582,8 @@ public function findNamespace($namespace)
|
563 | 582 | $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
|
564 | 583 |
|
565 | 584 | if (empty($namespaces)) {
|
| 585 | + $this->suggestPackage($namespace); |
| 586 | + |
566 | 587 | $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
|
567 | 588 |
|
568 | 589 | if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
|
@@ -1171,4 +1192,24 @@ private function init()
|
1171 | 1192 | $this->add($command);
|
1172 | 1193 | }
|
1173 | 1194 | }
|
| 1195 | + |
| 1196 | + /** |
| 1197 | + * Suggests a package, that should be installed via composer, |
| 1198 | + * if the package is missing, and the provided namespace can be mapped to a Symfony bundle. |
| 1199 | + * |
| 1200 | + * @param string $namespace A namespace to search for |
| 1201 | + * |
| 1202 | + * @return void |
| 1203 | + * |
| 1204 | + * @throws NamespaceNotFoundException When namespace is mapped to a Symfony bundle |
| 1205 | + */ |
| 1206 | + private function suggestPackage($namespace) { |
| 1207 | + if (isset(self::SUGGESTED_PACKAGES[$namespace])) { |
| 1208 | + $suggestion = self::SUGGESTED_PACKAGES[$namespace]; |
| 1209 | + |
| 1210 | + $message = sprintf("It seems that you are trying to run a command from '%s' bundle/package, but you do not have it installed. You may try installing the missing bundle/package by running:\n\n composer require %s", $suggestion[0], $suggestion[1]); |
| 1211 | + |
| 1212 | + throw new NamespaceNotFoundException($message); |
| 1213 | + } |
| 1214 | + } |
1174 | 1215 | }
|
0 commit comments