Application.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php
  2. namespace Symfony\Component\Console;
  3. use Symfony\Component\Console\Input\InputInterface;
  4. use Symfony\Component\Console\Input\ArgvInput;
  5. use Symfony\Component\Console\Input\ArrayInput;
  6. use Symfony\Component\Console\Input\InputDefinition;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Input\InputArgument;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. use Symfony\Component\Console\Output\Output;
  11. use Symfony\Component\Console\Output\ConsoleOutput;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Command\HelpCommand;
  14. use Symfony\Component\Console\Command\ListCommand;
  15. use Symfony\Component\Console\Helper\HelperSet;
  16. use Symfony\Component\Console\Helper\FormatterHelper;
  17. use Symfony\Component\Console\Helper\DialogHelper;
  18. /*
  19. * This file is part of the Symfony framework.
  20. *
  21. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  22. *
  23. * This source file is subject to the MIT license that is bundled
  24. * with this source code in the file LICENSE.
  25. */
  26. /**
  27. * An Application is the container for a collection of commands.
  28. *
  29. * It is the main entry point of a Console application.
  30. *
  31. * This class is optimized for a standard CLI environment.
  32. *
  33. * Usage:
  34. *
  35. * $app = new Application('myapp', '1.0 (stable)');
  36. * $app->add(new SimpleCommand());
  37. * $app->run();
  38. *
  39. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  40. */
  41. class Application
  42. {
  43. protected $commands;
  44. protected $aliases;
  45. protected $wantHelps = false;
  46. protected $runningCommand;
  47. protected $name;
  48. protected $version;
  49. protected $catchExceptions;
  50. protected $autoExit;
  51. protected $definition;
  52. protected $helperSet;
  53. /**
  54. * Constructor.
  55. *
  56. * @param string $name The name of the application
  57. * @param string $version The version of the application
  58. */
  59. public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
  60. {
  61. $this->name = $name;
  62. $this->version = $version;
  63. $this->catchExceptions = true;
  64. $this->autoExit = true;
  65. $this->commands = array();
  66. $this->aliases = array();
  67. $this->helperSet = new HelperSet(array(
  68. new FormatterHelper(),
  69. new DialogHelper(),
  70. ));
  71. $this->add(new HelpCommand());
  72. $this->add(new ListCommand());
  73. $this->definition = new InputDefinition(array(
  74. new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
  75. new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
  76. new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
  77. new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
  78. new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
  79. new InputOption('--ansi', '-a', InputOption::VALUE_NONE, 'Force ANSI output.'),
  80. new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
  81. ));
  82. }
  83. /**
  84. * Runs the current application.
  85. *
  86. * @param InputInterface $input An Input instance
  87. * @param OutputInterface $output An Output instance
  88. *
  89. * @return integer 0 if everything went fine, or an error code
  90. *
  91. * @throws \Exception When doRun returns Exception
  92. */
  93. public function run(InputInterface $input = null, OutputInterface $output = null)
  94. {
  95. if (null === $input) {
  96. $input = new ArgvInput();
  97. }
  98. if (null === $output) {
  99. $output = new ConsoleOutput();
  100. }
  101. try {
  102. $statusCode = $this->doRun($input, $output);
  103. } catch (\Exception $e) {
  104. if (!$this->catchExceptions) {
  105. throw $e;
  106. }
  107. $this->renderException($e, $output);
  108. $statusCode = $e->getCode();
  109. $statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1;
  110. }
  111. if ($this->autoExit) {
  112. if ($statusCode > 255) {
  113. $statusCode = 255;
  114. }
  115. // @codeCoverageIgnoreStart
  116. exit($statusCode);
  117. // @codeCoverageIgnoreEnd
  118. } else {
  119. return $statusCode;
  120. }
  121. }
  122. /**
  123. * Runs the current application.
  124. *
  125. * @param InputInterface $input An Input instance
  126. * @param OutputInterface $output An Output instance
  127. *
  128. * @return integer 0 if everything went fine, or an error code
  129. */
  130. public function doRun(InputInterface $input, OutputInterface $output)
  131. {
  132. $name = $this->getCommandName($input);
  133. if (true === $input->hasParameterOption(array('--ansi', '-a'))) {
  134. $output->setDecorated(true);
  135. }
  136. if (true === $input->hasParameterOption(array('--help', '-h'))) {
  137. if (!$name) {
  138. $name = 'help';
  139. $input = new ArrayInput(array('command' => 'help'));
  140. } else {
  141. $this->wantHelps = true;
  142. }
  143. }
  144. if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
  145. $input->setInteractive(false);
  146. }
  147. if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
  148. $output->setVerbosity(Output::VERBOSITY_QUIET);
  149. } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
  150. $output->setVerbosity(Output::VERBOSITY_VERBOSE);
  151. }
  152. if (true === $input->hasParameterOption(array('--version', '-V'))) {
  153. $output->writeln($this->getLongVersion());
  154. return 0;
  155. }
  156. if (!$name) {
  157. $name = 'list';
  158. $input = new ArrayInput(array('command' => 'list'));
  159. }
  160. // the command name MUST be the first element of the input
  161. $command = $this->find($name);
  162. $this->runningCommand = $command;
  163. $statusCode = $command->run($input, $output);
  164. $this->runningCommand = null;
  165. return is_numeric($statusCode) ? $statusCode : 0;
  166. }
  167. /**
  168. * Set a helper set to be used with the command.
  169. *
  170. * @param HelperSet $helperSet The helper set
  171. */
  172. public function setHelperSet(HelperSet $helperSet)
  173. {
  174. $this->helperSet = $helperSet;
  175. }
  176. /**
  177. * Get the helper set associated with the command
  178. *
  179. * @return HelperSet The HelperSet instance associated with this command
  180. */
  181. public function getHelperSet()
  182. {
  183. return $this->helperSet;
  184. }
  185. /**
  186. * Gets the InputDefinition related to this Application.
  187. *
  188. * @return InputDefinition The InputDefinition instance
  189. */
  190. public function getDefinition()
  191. {
  192. return $this->definition;
  193. }
  194. /**
  195. * Gets the help message.
  196. *
  197. * @return string A help message.
  198. */
  199. public function getHelp()
  200. {
  201. $messages = array(
  202. $this->getLongVersion(),
  203. '',
  204. '<comment>Usage:</comment>',
  205. sprintf(" [options] command [arguments]\n"),
  206. '<comment>Options:</comment>',
  207. );
  208. foreach ($this->definition->getOptions() as $option) {
  209. $messages[] = sprintf(' %-29s %s %s',
  210. '<info>--'.$option->getName().'</info>',
  211. $option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' : ' ',
  212. $option->getDescription()
  213. );
  214. }
  215. return implode("\n", $messages);
  216. }
  217. /**
  218. * Sets whether to catch exceptions or not during commands execution.
  219. *
  220. * @param Boolean $boolean Whether to catch exceptions or not during commands execution
  221. */
  222. public function setCatchExceptions($boolean)
  223. {
  224. $this->catchExceptions = (Boolean) $boolean;
  225. }
  226. /**
  227. * Sets whether to automatically exit after a command execution or not.
  228. *
  229. * @param Boolean $boolean Whether to automatically exit after a command execution or not
  230. */
  231. public function setAutoExit($boolean)
  232. {
  233. $this->autoExit = (Boolean) $boolean;
  234. }
  235. /**
  236. * Gets the name of the application.
  237. *
  238. * @return string The application name
  239. */
  240. public function getName()
  241. {
  242. return $this->name;
  243. }
  244. /**
  245. * Sets the application name.
  246. *
  247. * @param string $name The application name
  248. */
  249. public function setName($name)
  250. {
  251. $this->name = $name;
  252. }
  253. /**
  254. * Gets the application version.
  255. *
  256. * @return string The application version
  257. */
  258. public function getVersion()
  259. {
  260. return $this->version;
  261. }
  262. /**
  263. * Sets the application version.
  264. *
  265. * @param string $version The application version
  266. */
  267. public function setVersion($version)
  268. {
  269. $this->version = $version;
  270. }
  271. /**
  272. * Returns the long version of the application.
  273. *
  274. * @return string The long application version
  275. */
  276. public function getLongVersion()
  277. {
  278. if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {
  279. return sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());
  280. } else {
  281. return '<info>Console Tool</info>';
  282. }
  283. }
  284. /**
  285. * Registers a new command.
  286. *
  287. * @param string $name The command name
  288. *
  289. * @return Command The newly created command
  290. */
  291. public function register($name)
  292. {
  293. return $this->add(new Command($name));
  294. }
  295. /**
  296. * Adds an array of command objects.
  297. *
  298. * @param Command[] $commands An array of commands
  299. */
  300. public function addCommands(array $commands)
  301. {
  302. foreach ($commands as $command) {
  303. $this->add($command);
  304. }
  305. }
  306. /**
  307. * Adds a command object.
  308. *
  309. * If a command with the same name already exists, it will be overridden.
  310. *
  311. * @param Command $command A Command object
  312. *
  313. * @return Command The registered command
  314. */
  315. public function add(Command $command)
  316. {
  317. $command->setApplication($this);
  318. $this->commands[$command->getFullName()] = $command;
  319. foreach ($command->getAliases() as $alias) {
  320. $this->aliases[$alias] = $command;
  321. }
  322. return $command;
  323. }
  324. /**
  325. * Returns a registered command by name or alias.
  326. *
  327. * @param string $name The command name or alias
  328. *
  329. * @return Command A Command object
  330. *
  331. * @throws \InvalidArgumentException When command name given does not exist
  332. */
  333. public function get($name)
  334. {
  335. if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
  336. throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
  337. }
  338. $command = isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
  339. if ($this->wantHelps) {
  340. $this->wantHelps = false;
  341. $helpCommand = $this->get('help');
  342. $helpCommand->setCommand($command);
  343. return $helpCommand;
  344. }
  345. return $command;
  346. }
  347. /**
  348. * Returns true if the command exists, false otherwise
  349. *
  350. * @param string $name The command name or alias
  351. *
  352. * @return Boolean true if the command exists, false otherwise
  353. */
  354. public function has($name)
  355. {
  356. return isset($this->commands[$name]) || isset($this->aliases[$name]);
  357. }
  358. /**
  359. * Returns an array of all unique namespaces used by currently registered commands.
  360. *
  361. * It does not returns the global namespace which always exists.
  362. *
  363. * @return array An array of namespaces
  364. */
  365. public function getNamespaces()
  366. {
  367. $namespaces = array();
  368. foreach ($this->commands as $command) {
  369. if ($command->getNamespace()) {
  370. $namespaces[$command->getNamespace()] = true;
  371. }
  372. }
  373. return array_keys($namespaces);
  374. }
  375. /**
  376. * Finds a registered namespace by a name or an abbreviation.
  377. *
  378. * @return string A registered namespace
  379. *
  380. * @throws \InvalidArgumentException When namespace is incorrect or ambiguous
  381. */
  382. public function findNamespace($namespace)
  383. {
  384. $abbrevs = static::getAbbreviations($this->getNamespaces());
  385. if (!isset($abbrevs[$namespace])) {
  386. throw new \InvalidArgumentException(sprintf('There are no commands defined in the "%s" namespace.', $namespace));
  387. }
  388. if (count($abbrevs[$namespace]) > 1) {
  389. throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($abbrevs[$namespace])));
  390. }
  391. return $abbrevs[$namespace][0];
  392. }
  393. /**
  394. * Finds a command by name or alias.
  395. *
  396. * Contrary to get, this command tries to find the best
  397. * match if you give it an abbreviation of a name or alias.
  398. *
  399. * @param string $name A command name or a command alias
  400. *
  401. * @return Command A Command instance
  402. *
  403. * @throws \InvalidArgumentException When command name is incorrect or ambiguous
  404. */
  405. public function find($name)
  406. {
  407. // namespace
  408. $namespace = '';
  409. if (false !== $pos = strrpos($name, ':')) {
  410. $namespace = $this->findNamespace(substr($name, 0, $pos));
  411. $name = substr($name, $pos + 1);
  412. }
  413. $fullName = $namespace ? $namespace.':'.$name : $name;
  414. // name
  415. $commands = array();
  416. foreach ($this->commands as $command) {
  417. if ($command->getNamespace() == $namespace) {
  418. $commands[] = $command->getName();
  419. }
  420. }
  421. $abbrevs = static::getAbbreviations($commands);
  422. if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) {
  423. return $this->get($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
  424. }
  425. if (isset($abbrevs[$name]) && count($abbrevs[$name]) > 1) {
  426. $suggestions = $this->getAbbreviationSuggestions(array_map(function ($command) use ($namespace) { return $namespace.':'.$command; }, $abbrevs[$name]));
  427. throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $suggestions));
  428. }
  429. // aliases
  430. $abbrevs = static::getAbbreviations(array_keys($this->aliases));
  431. if (!isset($abbrevs[$fullName])) {
  432. throw new \InvalidArgumentException(sprintf('Command "%s" is not defined.', $fullName));
  433. }
  434. if (count($abbrevs[$fullName]) > 1) {
  435. throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $this->getAbbreviationSuggestions($abbrevs[$fullName])));
  436. }
  437. return $this->get($abbrevs[$fullName][0]);
  438. }
  439. /**
  440. * Gets the commands (registered in the given namespace if provided).
  441. *
  442. * The array keys are the full names and the values the command instances.
  443. *
  444. * @param string $namespace A namespace name
  445. *
  446. * @return array An array of Command instances
  447. */
  448. public function all($namespace = null)
  449. {
  450. if (null === $namespace) {
  451. return $this->commands;
  452. }
  453. $commands = array();
  454. foreach ($this->commands as $name => $command) {
  455. if ($namespace === $command->getNamespace()) {
  456. $commands[$name] = $command;
  457. }
  458. }
  459. return $commands;
  460. }
  461. /**
  462. * Returns an array of possible abbreviations given a set of names.
  463. *
  464. * @param array $names An array of names
  465. *
  466. * @return array An array of abbreviations
  467. */
  468. static public function getAbbreviations($names)
  469. {
  470. $abbrevs = array();
  471. foreach ($names as $name) {
  472. for ($len = strlen($name) - 1; $len > 0; --$len) {
  473. $abbrev = substr($name, 0, $len);
  474. if (!isset($abbrevs[$abbrev])) {
  475. $abbrevs[$abbrev] = array($name);
  476. } else {
  477. $abbrevs[$abbrev][] = $name;
  478. }
  479. }
  480. }
  481. // Non-abbreviations always get entered, even if they aren't unique
  482. foreach ($names as $name) {
  483. $abbrevs[$name] = array($name);
  484. }
  485. return $abbrevs;
  486. }
  487. /**
  488. * Returns a text representation of the Application.
  489. *
  490. * @param string $namespace An optional namespace name
  491. *
  492. * @return string A string representing the Application
  493. */
  494. public function asText($namespace = null)
  495. {
  496. $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
  497. $messages = array($this->getHelp(), '');
  498. if ($namespace) {
  499. $messages[] = sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $namespace);
  500. } else {
  501. $messages[] = '<comment>Available commands:</comment>';
  502. }
  503. $width = 0;
  504. foreach ($commands as $command) {
  505. $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
  506. }
  507. $width += 2;
  508. // add commands by namespace
  509. foreach ($this->sortCommands($commands) as $space => $commands) {
  510. if (!$namespace && '_global' !== $space) {
  511. $messages[] = '<comment>'.$space.'</comment>';
  512. }
  513. foreach ($commands as $command) {
  514. $aliases = $command->getAliases() ? '<comment> ('.implode(', ', $command->getAliases()).')</comment>' : '';
  515. $messages[] = sprintf(" <info>%-${width}s</info> %s%s", ($command->getNamespace() ? ':' : '').$command->getName(), $command->getDescription(), $aliases);
  516. }
  517. }
  518. return implode("\n", $messages);
  519. }
  520. /**
  521. * Returns an XML representation of the Application.
  522. *
  523. * @param string $namespace An optional namespace name
  524. * @param Boolean $asDom Whether to return a DOM or an XML string
  525. *
  526. * @return string|DOMDocument An XML string representing the Application
  527. */
  528. public function asXml($namespace = null, $asDom = false)
  529. {
  530. $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
  531. $dom = new \DOMDocument('1.0', 'UTF-8');
  532. $dom->formatOutput = true;
  533. $dom->appendChild($xml = $dom->createElement('symfony'));
  534. $xml->appendChild($commandsXML = $dom->createElement('commands'));
  535. if ($namespace) {
  536. $commandsXML->setAttribute('namespace', $namespace);
  537. } else {
  538. $xml->appendChild($namespacesXML = $dom->createElement('namespaces'));
  539. }
  540. // add commands by namespace
  541. foreach ($this->sortCommands($commands) as $space => $commands) {
  542. if (!$namespace) {
  543. $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
  544. $namespaceArrayXML->setAttribute('id', $space);
  545. }
  546. foreach ($commands as $command) {
  547. if (!$namespace) {
  548. $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
  549. $commandXML->appendChild($dom->createTextNode($command->getName()));
  550. }
  551. $node = $command->asXml(true)->getElementsByTagName('command')->item(0);
  552. $node = $dom->importNode($node, true);
  553. $commandsXML->appendChild($node);
  554. }
  555. }
  556. return $asDom ? $dom : $dom->saveXml();
  557. }
  558. /**
  559. * Renders a catched exception.
  560. *
  561. * @param Exception $e An exception instance
  562. * @param OutputInterface $output An OutputInterface instance
  563. */
  564. public function renderException($e, $output)
  565. {
  566. $strlen = function ($string)
  567. {
  568. return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
  569. };
  570. do {
  571. $title = sprintf(' [%s] ', get_class($e));
  572. $len = $strlen($title);
  573. $lines = array();
  574. foreach (explode("\n", $e->getMessage()) as $line) {
  575. $lines[] = sprintf(' %s ', $line);
  576. $len = max($strlen($line) + 4, $len);
  577. }
  578. $messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title)));
  579. foreach ($lines as $line) {
  580. $messages[] = $line.str_repeat(' ', $len - $strlen($line));
  581. }
  582. $messages[] = str_repeat(' ', $len);
  583. $output->writeln("\n");
  584. foreach ($messages as $message) {
  585. $output->writeln('<error>'.$message.'</error>');
  586. }
  587. $output->writeln("\n");
  588. if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
  589. $output->writeln('</comment>Exception trace:</comment>');
  590. // exception related properties
  591. $trace = $e->getTrace();
  592. array_unshift($trace, array(
  593. 'function' => '',
  594. 'file' => $e->getFile() != null ? $e->getFile() : 'n/a',
  595. 'line' => $e->getLine() != null ? $e->getLine() : 'n/a',
  596. 'args' => array(),
  597. ));
  598. for ($i = 0, $count = count($trace); $i < $count; $i++) {
  599. $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
  600. $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
  601. $function = $trace[$i]['function'];
  602. $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
  603. $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
  604. $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
  605. }
  606. $output->writeln("\n");
  607. }
  608. } while ($e = $e->getPrevious());
  609. if (null !== $this->runningCommand) {
  610. $output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
  611. $output->writeln("\n");
  612. }
  613. }
  614. protected function getCommandName(InputInterface $input)
  615. {
  616. return $input->getFirstArgument('command');
  617. }
  618. protected function sortCommands($commands)
  619. {
  620. $namespacedCommands = array();
  621. foreach ($commands as $name => $command) {
  622. $key = $command->getNamespace() ? $command->getNamespace() : '_global';
  623. if (!isset($namespacedCommands[$key])) {
  624. $namespacedCommands[$key] = array();
  625. }
  626. $namespacedCommands[$key][$name] = $command;
  627. }
  628. ksort($namespacedCommands);
  629. foreach ($namespacedCommands as $name => &$commands) {
  630. ksort($commands);
  631. }
  632. return $namespacedCommands;
  633. }
  634. protected function getAbbreviationSuggestions($abbrevs)
  635. {
  636. return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
  637. }
  638. }