jeudi 3 novembre 2022

Instance class by some rule

I have some function converting some tag to class name.

function($tag): string {
    return '\App\Services\MyUglyServices\' . ucfirst(Str::camel($tag));
}

I want to instance some class by corresponding tag name. For example:

$obj = app('tag:my_ugly_service');
echo get_class($obj); // I want it to be \App\Services\MyUglyServices\MyUglyService

Is there any way to do it using service providers?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire