1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\ShowUnusedComposerPackages; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command as BaseCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Symfony-Console-Command wrapper for the ShowUnusedComposerPackages task. |
14
|
|
|
*/ |
15
|
|
|
final class Command extends BaseCommand |
16
|
|
|
{ |
17
|
|
|
const ARGUMENT_COMPOSER_JSON = 'composerJson'; |
18
|
|
|
const OPTION_VENDOR_DIRECTORY = 'vendorDir'; |
19
|
|
|
const ARGUMENT_USED_FILES = 'usedFiles'; |
20
|
|
|
const OPTION_PATH_TO_BLACKLIST = 'pathToBlacklist'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Task |
24
|
|
|
*/ |
25
|
|
|
private $task; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Task $task |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Task $task) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
$this->task = $task; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
protected function configure() |
40
|
|
|
{ |
41
|
|
|
$this->setName('show-unused-composer-packages') |
42
|
|
|
->setDescription('Show a list of potentially unused composer packages.') |
43
|
|
|
->addArgument(self::ARGUMENT_COMPOSER_JSON, InputArgument::REQUIRED, 'Path to the project\'s composer.json.') |
44
|
|
|
->addOption(self::OPTION_VENDOR_DIRECTORY, 'l', InputOption::VALUE_REQUIRED, 'Path to the project\'s vendor directory.') |
45
|
|
|
->addArgument(self::ARGUMENT_USED_FILES, InputArgument::REQUIRED, 'Path to the list of used files.') |
46
|
|
|
->addOption(self::OPTION_PATH_TO_BLACKLIST, 'b', InputOption::VALUE_REQUIRED, 'Path to a file containing a blacklist of regular expressions to exclude from the output. One regular expression per line, don\'t forget the delimiters. E.g.: ' . PHP_EOL . '#^/project/keepme.php#' . PHP_EOL . '#^/project/tmp/#' . PHP_EOL . '#.*Test.php#'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
$this->task->getUnusedPackagePaths( |
55
|
|
|
$input->getArgument(self::ARGUMENT_COMPOSER_JSON), |
|
|
|
|
56
|
|
|
$input->getOption(self::OPTION_VENDOR_DIRECTORY), |
|
|
|
|
57
|
|
|
$input->getArgument(self::ARGUMENT_USED_FILES), |
|
|
|
|
58
|
|
|
$input->getOption(self::OPTION_PATH_TO_BLACKLIST), |
|
|
|
|
59
|
|
|
new SymfonyStyle($input, $output) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|