StatsDevicesCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace StatsBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Output\OutputInterface;
  6. use StatsBundle\Services\DeviceManager;
  7. class StatsDevicesCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. ->setName('stats:devices')
  13. ->setDescription('Stats Devices command')
  14. ->setHelp('This command allows you to get and update stats devices list from devices server url')
  15. ;
  16. }
  17. /**
  18. * @param InputInterface $input
  19. * @param OutputInterface $output
  20. */
  21. protected function execute(InputInterface $input, OutputInterface $output)
  22. {
  23. /* @var $statsDeviceManager DeviceManager */
  24. $statsDeviceManager = $this->getContainer()->get('stats.device.manager');
  25. $devices = $statsDeviceManager->getDevices();
  26. if (count($devices)) {
  27. $output->writeln('Nuevos StatsDevice:');
  28. foreach ($devices as $device) {
  29. $output->writeln(sprintf('<info>DeviceType:</info> %s <info>DeviceIp:</info> %s', $device->getDeviceType(), $device->getIp()));
  30. }
  31. } else {
  32. $output->writeln('No hay nuevos StatsDevice');
  33. }
  34. }
  35. }