Shell.php

  1. 8.0.x lib/Drush/Psysh/Shell.php
  2. master lib/Drush/Psysh/Shell.php

Contains \Drush\Psysh\Shell.

Namespace

Drush\Psysh

Classes

Namesort descending Description
Shell

File

lib/Drush/Psysh/Shell.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drush\Psysh\Shell.
  5. */
  6. namespace Drush\Psysh;
  7. use Psy\Shell as BaseShell;
  8. use Symfony\Component\Console\Input\StringInput;
  9. class Shell extends BaseShell {
  10. /**
  11. * Get a command (if one exists) for the current input string.
  12. *
  13. * @param string $input
  14. *
  15. * @return null|Command
  16. */
  17. protected function getCommand($input) {
  18. if ($name = $this->getCommandFromInput($input)) {
  19. return $this->get($name);
  20. }
  21. }
  22. /**
  23. * Check whether a command is set for the current input string.
  24. *
  25. * @param string $input
  26. *
  27. * @return bool True if the shell has a command for the given input.
  28. */
  29. protected function hasCommand($input) {
  30. if ($name = $this->getCommandFromInput($input)) {
  31. return $this->has($name);
  32. }
  33. return false;
  34. }
  35. /**
  36. * Get the command from the current input, takes aliases into account.
  37. *
  38. * @param string $input
  39. * The raw input
  40. *
  41. * @return string|NULL
  42. * The current command.
  43. */
  44. protected function getCommandFromInput($input) {
  45. // Remove the alias from the start of the string before parsing and
  46. // returning the command. Essentially, when choosing a command, we're
  47. // ignoring the site alias.
  48. $input = preg_replace('|^\@[^\s]+|', '', $input);
  49. $input = new StringInput($input);
  50. return $input->getFirstArgument();
  51. }
  52. }