1: <?php
2: namespace Contrib\Bundle\CoverallsBundle\Console;
3:
4: use Contrib\Bundle\CoverallsV1Bundle\Command\CoverallsV1JobsCommand;
5: use Symfony\Component\Console\Application as BaseApplication;
6: use Symfony\Component\Console\Input\InputInterface;
7:
8: /**
9: * Coveralls API application.
10: *
11: * @author Kitamura Satoshi <with.no.parachute@gmail.com>
12: */
13: class Application extends BaseApplication
14: {
15: /**
16: * Path to project root directory.
17: *
18: * @var string
19: */
20: private $rootDir;
21:
22: /**
23: * Constructor.
24: *
25: * @param string $rootDir Path to project root directory.
26: * @param string $name The name of the application
27: * @param string $version The version of the application
28: */
29: public function __construct($rootDir, $name = 'UNKNOWN', $version = 'UNKNOWN')
30: {
31: $this->rootDir = $rootDir;
32:
33: parent::__construct($name, $version);
34: }
35:
36: // internal method
37:
38: /**
39: * {@inheritdoc}
40: *
41: * @see \Symfony\Component\Console\Application::getCommandName()
42: */
43: protected function getCommandName(InputInterface $input)
44: {
45: return 'coveralls:v1:jobs';
46: }
47:
48: /**
49: * {@inheritdoc}
50: *
51: * @see \Symfony\Component\Console\Application::getDefaultCommands()
52: */
53: protected function getDefaultCommands()
54: {
55: // Keep the core default commands to have the HelpCommand
56: // which is used when using the --help option
57: $defaultCommands = parent::getDefaultCommands();
58:
59: $defaultCommands[] = $this->createCoverallsV1JobsCommand();
60:
61: return $defaultCommands;
62: }
63:
64: /**
65: * Create CoverallsV1JobsCommand.
66: *
67: * @return \Contrib\Bundle\CoverallsBundle\Console\CoverallsV1JobsCommand
68: */
69: protected function createCoverallsV1JobsCommand()
70: {
71: $command = new CoverallsV1JobsCommand();
72: $command->setRootDir($this->rootDir);
73:
74: return $command;
75: }
76:
77: // accessor
78:
79: /**
80: * {@inheritdoc}
81: *
82: * @see \Symfony\Component\Console\Application::getDefinition()
83: */
84: public function getDefinition()
85: {
86: $inputDefinition = parent::getDefinition();
87: // clear out the normal first argument, which is the command name
88: $inputDefinition->setArguments();
89:
90: return $inputDefinition;
91: }
92: }
93: