Skip to content

Anonymous services for the fluent PHP format #24493

Closed
@unkind

Description

@unkind

Sometimes I don't care about service name at all, e.g. when I decorate service or when I make service which is meant to be injected by CompilerPass (listeners, command handlers, ....). If I have multiple services for the same class, I'm not able to simply use class name as a service name.

Does it make sense to introduce something like anonymous services (ServicesConfigurator):

    final public function anonymous(string $class)
    {
        return $this->set(uniqid(), $class)->private();
    }

? (service name should be determined for tests, but I want to show the idea).

Also current configuration of decorated services is not well-compatible with anonymous services above. I want to see something like

return function (ContainerConfigurator $c) {
    $c->anonymous(CacheFooDecorator::class)
        ->decorate(Foo::class)
        ->args(
            decorated(), // injects Foo service
            ref('memcache'),
            // ...
        );
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions