CommandProvider.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Installer;
  3. use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Output\OutputInterface;
  6. use Composer\Command\BaseCommand;
  7. class CommandProvider implements CommandProviderCapability
  8. {
  9. public function __construct(array $args)
  10. {
  11. if (!$args['composer'] instanceof \Composer\Composer) {
  12. throw new \RuntimeException('Expected a "composer" key');
  13. }
  14. if (!$args['io'] instanceof \Composer\IO\IOInterface) {
  15. throw new \RuntimeException('Expected an "io" key');
  16. }
  17. if (!$args['plugin'] instanceof Plugin8) {
  18. throw new \RuntimeException('Expected a "plugin" key with my own plugin');
  19. }
  20. }
  21. public function getCommands()
  22. {
  23. return array(new Command);
  24. }
  25. }
  26. class Command extends BaseCommand
  27. {
  28. protected function configure()
  29. {
  30. $this->setName('custom-plugin-command');
  31. }
  32. protected function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. $output->writeln('Executing');
  35. return 5;
  36. }
  37. }