GearmanCheckCommand.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Mmoreramerino\GearmanBundle\Command;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputDefinition;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Mmoreramerino\GearmanBundle\Service\GearmanSettings;
  9. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  10. use Mmoreramerino\GearmanBundle\Exceptions\GearmanNotInstalledException;
  11. use Mmoreramerino\GearmanBundle\Exceptions\NoSettingsFileExistsException;
  12. /**
  13. * Checks gearman environment
  14. *
  15. * @author Marc Morera <marc@ulabox.com>
  16. */
  17. class GearmanCheckCommand extends ContainerAwareCommand
  18. {
  19. /**
  20. * Console Command configuration
  21. */
  22. protected function configure()
  23. {
  24. parent::configure();
  25. $this->setName('gearman:check')
  26. ->setDescription('Checks gearman environment');
  27. }
  28. /**
  29. * Executes the current command.
  30. *
  31. * @param InputInterface $input An InputInterface instance
  32. * @param OutputInterface $output An OutputInterface instance
  33. *
  34. * @return integer 0 if everything went fine, or an error code
  35. *
  36. * @throws \LogicException When this abstract class is not implemented
  37. */
  38. protected function execute(InputInterface $input, OutputInterface $output)
  39. {
  40. if (!in_array('gearman', get_loaded_extensions())) {
  41. throw new GearmanNotInstalledException;
  42. } else {
  43. $output->writeln('<comment>* Checking gearman extension...</comment>');
  44. }
  45. $gearmanSettings = $this->getContainer()->get('gearman.settings');
  46. if (!$gearmanSettings->existsSettings()) {
  47. throw new NoSettingsFileExistsException($this->getFilePath());
  48. } else {
  49. $output->writeln('<comment>* Checking gearman settings file...</comment>');
  50. }
  51. $output->writeln('<comment>Gearman is succesfuly installed</comment>');
  52. }
  53. }