Skip to content
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

Autowire services that implement NamerInterface #1448

Open
tacman opened this issue May 4, 2024 · 3 comments
Open

Autowire services that implement NamerInterface #1448

tacman opened this issue May 4, 2024 · 3 comments

Comments

@tacman
Copy link
Contributor

tacman commented May 4, 2024

Feature Request

Q A
New Feature yes
BC Break no

Summary

Instead or requiring namer services to be manually registered.

# services.yaml
    App\Service\ProjectImageNamerService:
        public: true

The compiler pass could look for services that implement NamerInterface and make them public. One less step when creating a custom namer service.

@garak
Copy link
Collaborator

garak commented May 4, 2024

If we have to add a compiler pass, why don't do something to properly inject the configured service for the namer?
So, we can make all the namers private again.

@garak
Copy link
Collaborator

garak commented May 6, 2024

To elaborate a bit on my previous comment: I was thinking about injecting two services into PropertyMappingResolver, a NamerInterface and an optional DirectoryNamerInterface.
The definition would be empty in the service configuration, and the compiler pass should resolve these two services.

PRs are welcome.

@tacman
Copy link
Contributor Author

tacman commented May 6, 2024

A directory namer would be cool. In fact, my custom namer really is only the directory.

$file = $mapping->getFile($object);
$name = $file->getClientOriginalName();

/** @var $object Project|Asset */
$name = match ($object::class) {
    Project::class => sprintf("%s/%s", $object->getSlug(), $name),
    Asset::class => sprintf("%s/%s/%s", $object->getProject()->getSlug(), $object->getItem()->getCode(), $name),
};
return $name;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants