Skip to content

Commit 174a960

Browse files
committed
extract application from bin stub
1 parent 5389100 commit 174a960

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

bin/symfony-autocomplete

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,14 @@
11
#!/usr/bin/env php
22
<?php
33

4-
use Bamarni\Symfony\Console\Autocomplete\DumpCommand;
5-
use Symfony\Component\Console\Application as BaseApplication;
6-
use Symfony\Component\Console\Command\Command;
7-
use Symfony\Component\Console\Input\InputDefinition;
8-
use Symfony\Component\Console\Input\InputInterface;
94

105
if (file_exists($autoload = __DIR__.'/../../../autoload.php')) {
116
require_once $autoload;
127
} else {
138
require_once __DIR__.'/../vendor/autoload.php';
149
}
1510

16-
class Application extends BaseApplication
17-
{
18-
private $command;
11+
use Bamarni\Symfony\Console\Autocomplete\Application;
1912

20-
public function __construct(Command $command)
21-
{
22-
$this->command = $command;
23-
24-
parent::__construct();
25-
}
26-
27-
protected function getCommandName(InputInterface $input): ?string
28-
{
29-
return $this->command->getName();
30-
}
31-
32-
protected function getDefaultCommands(): array
33-
{
34-
$defaultCommands = parent::getDefaultCommands();
35-
$defaultCommands[] = $this->command;
36-
37-
return $defaultCommands;
38-
}
39-
40-
public function getDefinition(): InputDefinition
41-
{
42-
$inputDefinition = parent::getDefinition();
43-
$inputDefinition->setArguments();
44-
45-
return $inputDefinition;
46-
}
47-
}
48-
49-
$console = new Application(new DumpCommand);
13+
$console = new Application();
5014
$console->run();

src/Application.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Bamarni\Symfony\Console\Autocomplete;
4+
5+
use Symfony\Component\Console\Application as BaseApplication;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputDefinition;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
10+
class Application extends BaseApplication
11+
{
12+
private $command;
13+
14+
public function __construct(Command $command = null)
15+
{
16+
$this->command = $command ?? new DumpCommand;
17+
18+
parent::__construct();
19+
}
20+
21+
protected function getCommandName(InputInterface $input): ?string
22+
{
23+
return $this->command->getName();
24+
}
25+
26+
protected function getDefaultCommands(): array
27+
{
28+
$defaultCommands = parent::getDefaultCommands();
29+
$defaultCommands[] = $this->command;
30+
31+
return $defaultCommands;
32+
}
33+
34+
public function getDefinition(): InputDefinition
35+
{
36+
$inputDefinition = parent::getDefinition();
37+
$inputDefinition->setArguments();
38+
39+
return $inputDefinition;
40+
}
41+
}

0 commit comments

Comments
 (0)