0

In an existing Symfony console app, I achieved a modified output I wanted to do (as a proof-of-concept exercise) by changing this class:

vendor/symfony/console/Helper/DescriptorHelper.php

I changed this method:

protected function describeApplication(Application $application, array $options = []): void

and added a couple of auxiliary private methods.

But now I want to do it "the right way", with some kind of class extension or decoration instead of changing the core classes in vendor directory.

How can that be elegantly achieved in a way that any code calling the "old" TextDescriptor gets my class instead?

(I was reading about decoration, this seemed a good case for it, but it seems that the decorating classes can only see the public methods of the decorated class, so this one wouldn't be available to me...)

2
  • I don't see an option to extend TextDescriptor. You can see here it is instantiated with new keyword. So there are no options to dynamically replace it with your class. Commented Jan 14 at 11:28
  • Ok, thanks, I think you're right. I also asked here github.com/symfony/symfony/discussions/59437 and I got a helpful pointer: use composer to change the code. Two ways of doing this: composer patches to swap out bits of code; and composer autoload rules to swap out the entire class. But these are external solutions, not merely Symfony mechanisms. Commented Jan 15 at 11:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.