Skip to content

Commit

Permalink
feat: add support for lazily-loaded commands, which are wrapped in a …
Browse files Browse the repository at this point in the history
…LazyCommand, which doesn't have the expected @job annotations itself. (#11)
  • Loading branch information
CodeCasterNL authored Jan 18, 2022
1 parent f73618b commit cf521d9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Padam87\CronBundle\Annotation\Job;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\LazyCommand;
use Symfony\Component\Console\Input\InputInterface;

class Helper
Expand All @@ -23,7 +24,11 @@ public function createTab(InputInterface $input, ?array $config = null): Tab
$tab = new Tab();

foreach($this->application->all() as $command) {
$annotations = $this->annotationReader->getClassAnnotations(new \ReflectionClass($command));
$commandInstance = $command instanceof LazyCommand
? $command->getCommand()
: $command;

$annotations = $this->annotationReader->getClassAnnotations(new \ReflectionClass($commandInstance));

foreach ($annotations as $annotation) {
if ($annotation instanceof Job) {
Expand All @@ -37,7 +42,7 @@ public function createTab(InputInterface $input, ?array $config = null): Tab
'%s %s %s',
$config['php_binary'],
realpath($_SERVER['argv'][0]),
$annotation->commandLine === null ? $command->getName() : $annotation->commandLine
$annotation->commandLine === null ? $commandInstance->getName() : $annotation->commandLine
);

if ($config['log_dir'] !== null && $annotation->logFile !== null) {
Expand Down

0 comments on commit cf521d9

Please sign in to comment.