Application.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\CommandLine;
  3. use ThurData\Servers\KerioEmail\Core\ModuleConstants;
  4. class Application extends \Symfony\Component\Console\Application
  5. {
  6. protected $dir = '';
  7. /**
  8. * @override
  9. */
  10. public function run()
  11. {
  12. $this->loadCommandsControllers($this->getCommands());
  13. parent::run();
  14. }
  15. /**
  16. * Get all available files
  17. * @return array
  18. */
  19. protected function getCommands()
  20. {
  21. $files = glob(ModuleConstants::getFullPath('app', $this->dir).'/*.php');
  22. $commands = [];
  23. foreach($files as $file)
  24. {
  25. $file = substr($file, strrpos($file, DIRECTORY_SEPARATOR)+1);
  26. $file = substr($file, 0, strrpos($file, '.'));
  27. $commands[] = $file;
  28. }
  29. return $commands;
  30. }
  31. /**
  32. * Create new objects and add it
  33. * @param $commands
  34. */
  35. protected function loadCommandsControllers($commands)
  36. {
  37. foreach($commands as $command)
  38. {
  39. $class = ModuleConstants::getRootNamespace().'\App\\'.$this->dir.'\\'.$command;
  40. $this->add(new $class);
  41. }
  42. }
  43. }