console-extra icon indicating copy to clipboard operation
console-extra copied to clipboard

Argument Resolvers

Open simoheinonen opened this issue 1 year ago • 4 comments

Would be nice to have https://symfony.com/doc/current/controller/value_resolver.html for commands:

public function __invoke(
  #[Argument]
  User $user,
) {

simoheinonen avatar Sep 19 '24 13:09 simoheinonen

What do you think the argument parameters should be to do that mapping? That is, if I want to look up a user by email, how should that mapping happen?

public function __invoke(
  #[Argument(name: 'email']
  User $user,
  #[Option(name: 'projectCode', alias: 'p', map: ['projectCode' => 'code']
  Project $project,
) {
bin/console app:create-project-admin [email protected] -p bobsProject 

I think this would be great, I have a lot of boilerplate code that is just mapping from an argument or option string to an entity.

tacman avatar Jan 03 '25 12:01 tacman

Yeah something like that! Primary key by default I guess

simoheinonen avatar Jan 03 '25 17:01 simoheinonen

Some of this packages features are now in 7.3: https://symfony.com/blog/new-in-symfony-7-3-invokable-commands-and-input-attributes with hopefully argument resolvers coming soon!

kbond avatar May 21 '25 22:05 kbond

Argument resolver would rock! In the meantime, for the command generator I've been working on we're looking at how to inject the property entity repository and do the lookup.

I wish Symfony's make:entity did not generate an auto-increment primary key by default. In many cases, there's a field available for the PK. I've toyed with a custom generator that allows the developer to decide auto-increment or a field (ISBN, SSN, code, wikiCode, etc)

tacman avatar May 21 '25 22:05 tacman