1 | <?php |
||
16 | class SilverstripeApplication extends SymfonyApplication |
||
|
|||
17 | { |
||
18 | /** |
||
19 | * The output from the previous command. |
||
20 | * |
||
21 | * @var \Symfony\Component\Console\Output\BufferedOutput |
||
22 | */ |
||
23 | protected $lastOutput; |
||
24 | |||
25 | public function __construct() |
||
26 | { |
||
27 | parent::__construct(); |
||
28 | |||
29 | $this->loadCommands(); |
||
30 | |||
31 | $this->add($default = new DefaultCommand()); |
||
32 | $this->setDefaultCommand($default->getName()); |
||
33 | |||
34 | $this->setAutoExit(false); |
||
35 | $this->setCatchExceptions(false); |
||
36 | } |
||
37 | |||
38 | public function run(InputInterface $input = null, OutputInterface $output = null) |
||
39 | { |
||
40 | return parent::run($input, $output); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Run an Artisan console command by name. |
||
45 | * |
||
46 | * @param string $command |
||
47 | * @param array $parameters |
||
48 | * |
||
49 | * @return int |
||
50 | */ |
||
51 | public function call($command, array $parameters = []) |
||
52 | { |
||
53 | $parameters = array_merge((array) $command, $parameters); |
||
54 | |||
55 | $this->lastOutput = new BufferedOutput(); |
||
56 | |||
57 | $this->setCatchExceptions(false); |
||
58 | |||
59 | $result = $this->run(new ArrayInput($parameters), $this->lastOutput); |
||
60 | |||
61 | $this->setCatchExceptions(true); |
||
62 | |||
63 | return $result; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get the output for the last run command. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | public function output() |
||
75 | |||
76 | /** |
||
77 | * Add a command to the console. |
||
78 | * |
||
79 | * @param \Symfony\Component\Console\Command\Command $command |
||
80 | * |
||
81 | * @return \Symfony\Component\Console\Command\Command |
||
82 | */ |
||
83 | public function add(SymfonyCommand $command) |
||
87 | |||
88 | /** |
||
89 | * Add the command to the parent instance. |
||
90 | * |
||
91 | * @param \Symfony\Component\Console\Command\Command $command |
||
92 | * |
||
93 | * @return \Symfony\Component\Console\Command\Command |
||
94 | */ |
||
95 | protected function addToParent(SymfonyCommand $command) |
||
99 | |||
100 | /** |
||
101 | * Get the default input definitions for the applications. |
||
102 | * |
||
103 | * This is used to add the --env option to every available command. |
||
104 | * |
||
105 | * @return \Symfony\Component\Console\Input\InputDefinition |
||
106 | */ |
||
107 | protected function getDefaultInputDefinition() |
||
115 | |||
116 | /** |
||
117 | * Get the global environment option for the definition. |
||
118 | * |
||
119 | * @return \Symfony\Component\Console\Input\InputOption |
||
120 | */ |
||
121 | protected function getEnvironmentOption() |
||
127 | |||
128 | /** |
||
129 | * Load all available commands into the console application. |
||
130 | */ |
||
131 | protected function loadCommands() |
||
145 | |||
146 | /** |
||
147 | * When developing and renaming or removing a Command, the manifest is not always updated. |
||
148 | * |
||
149 | * We don't want file_not_found or class_does_not_exists error for commands, |
||
150 | * because that prevente running commands like cache:clear etc. |
||
151 | * |
||
152 | * @param string $class |
||
153 | * @param string $path |
||
154 | */ |
||
155 | protected function addCommandOrSilentlyFail($class, $path) |
||
164 | |||
165 | } |
||
166 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.