简体   繁体   中英

Symfony Override Command Class from third-party Bundle

I have a project in which i am using JMose's Command Scheduler Bundle in order to create a cronjob manager. The cronjob Manager handles my own custom Symfony command parse:source .

The problem is that this repo is handling Exceptions and throwing errors back on the command console which would be very neat if it included the $e->getLine() method in order for the exception message to be printed along with the line that produced it. You can see his code below.

    try {
        $output->writeln('<info>Execute</info> : <comment>' . $scheduledCommand->getCommand()
            . ' ' . $scheduledCommand->getArguments() . '</comment>');
        $result = $command->run($input, $logOutput);
    } catch (\Exception $e) {
        $logOutput->writeln($e->getMessage());
        $logOutput->writeln($e->getTraceAsString());
        $result = -1;
    }

What I want is to override his class in order add that line of code. I have tried that without luck and I was not able to find help on Symfony documentation site.

My current project structure looks something like that. I have highlighted the class ExecuteCommand because it is the class that I want to override.

在此处输入图片说明

Run the command in verbose mode:

php bin/console parse:source -v

Use the Symfony console events: https://symfony.com/doc/3.4/components/console/events.html

There is an event called: EXCEPTION or console.exception where you can catch any command exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM