Skip to content

Getting requested name when using wildcards #269

@AydinHassan

Description

@AydinHassan

Hi, I tried to look through the docs and code about wilcard definitions but couldn't find what I wanted. Is it possible to get the requested service name in a wildcard factory?

return [
    'Vendor\Package\Command\*Command' => factory(function (Container $c, $requestedName) {
        $cmd = explode("\\", $requestedName)[3]; //DeployCommand
        $cmd = substr($cmd, 0, -7); //Deploy
        $commandService = $c->get(sprintf('%s/Service', $cmd));
        return new $requestedName($commandService);
    }),
];

Maybe there is a better way to do what I am trying to accomplish?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions