You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/GenerateStubsCommand.php
+19-1Lines changed: 19 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,7 @@ public function configure(): void
59
59
->addOption('out', null, InputOption::VALUE_REQUIRED, 'Path to a file to write pretty-printed stubs to. If unset, stubs will be written to stdout.')
60
60
->addOption('force', null, InputOption::VALUE_NONE, 'Whether to force an overwrite.')
61
61
->addOption('finder', null, InputOption::VALUE_REQUIRED, 'Path to a PHP file which returns a `Symfony\Finder` instance including the set of files that should be parsed. Can be used instead of, but not in addition to, passing sources directly.')
62
+
->addOption('visitor', null, InputOption::VALUE_REQUIRED, 'Path to a PHP file which returns a `StubsGenerator\NodeVisitor` instance to replace the default node visitor.')
62
63
->addOption('header', null, InputOption::VALUE_REQUIRED, 'A doc comment to prepend to the top of the generated stubs file. (Will be added below the opening `<?php` tag.)', '')
63
64
->addOption('nullify-globals', null, InputOption::VALUE_NONE, 'Initialize all global variables with a value of `null`, instead of their assigned value.')
64
65
->addOption('stats', null, InputOption::VALUE_NONE, 'Whether to print stats instead of outputting stubs. Stats will always be printed if --out is provided.');
@@ -95,13 +96,30 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
95
96
protectedfunctionexecute(InputInterface$input, OutputInterface$output): int
96
97
{
97
98
$io = newSymfonyStyle($input, $output);
99
+
$visitor = null;
100
+
$visitorPath = $input->getOption('visitor');
101
+
102
+
if ($visitorPath) {
103
+
$visitorPath = $this->resolvePath($visitorPath);
104
+
if (!$this->filesystem->exists($visitorPath) || is_dir($visitorPath)) {
105
+
thrownewInvalidArgumentException("Bad --visitor path: '$visitorPath' does not exist or is a directory.");
106
+
}
107
+
try {
108
+
$visitor = @include$visitorPath;
109
+
} catch (Exception$e) {
110
+
thrownewRuntimeException("Could not resolve a `StubsGenerator\NodeVisitor` from '$visitorPath'.", 0, $e);
111
+
}
112
+
if (!$visitor || !($visitorinstanceof NodeVisitor)) {
113
+
thrownewRuntimeException("Could not resolve a `StubsGenerator\NodeVisitor` from '$visitorPath'.");
0 commit comments