-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[make:decorator] Add new maker to create decorator #1613
base: main
Are you sure you want to change the base?
Conversation
c606c72
to
dbbc516
Compare
src/Maker/MakeDecorator.php
Outdated
|
||
($question = new Question($argument->getDescription())) | ||
->setAutocompleterValues($this->ids) | ||
->setValidator(fn ($answer) => Validator::serviceExists($answer, $this->ids)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on the issue I'd suggest that the command accept not only the id but a classname and tries to guess the id based on it (if the service does not exists for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try something like that:
- If the class is use as ID => easy found
- If no id with the classname, try to find one service using it
- If more then one service, suggest to choose which service to decorate?
- If nothing found, just exit with error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 yes with fault tolerance maybe ? serializer
vs serialiser
There are example in symfony's code about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I also did guess from class/interface short name.
$command | ||
->addArgument('id', InputArgument::OPTIONAL, 'The ID of the service to decorate.') | ||
->addArgument('decorator-class', InputArgument::OPTIONAL, \sprintf('The class name of the service to create (e.g. <fg=yellow>%sDecorator</>)', Str::asClassName(Str::getRandomTerm()))) | ||
->setHelp($this->getHelpFileContents('MakeDecorator.txt')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
priority
and onInvalid
could be added as options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
return 'service_a'; | ||
} | ||
|
||
public function getDefault(string $mode = self::MODE_FOO): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use this test to check different argument representations. Ex: without type, without default value, PHP8 attributes, variadic arguments, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I test it here tests/Util/ClassSource/ClassMethodTest.php#L62
Is it enough?
c815fab
to
2fb5feb
Compare
src/Maker/MakeDecorator.php
Outdated
|
||
public static function getCommandDescription(): string | ||
{ | ||
return 'Create CRUD for Doctrine entity class'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 'Create CRUD for Doctrine entity class'; | |
return 'Create a decorator of a service class'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
…ity/onInvalid Also fix: - ignore `__construct` - fix static method on decorate by implements - Fix description
Add new maker to create decorator.
#1401
Allow to create new decorator for existing services.
It try first to decorate by implements:
If cannot implements, it will fallback to extends:
e.g.