RuntimeException: The service "currency_converter" does not exist (using laravel-swap)
alies-dev opened this issue · comments
Note that this error happened on using of currently undocumented functionality (florianv/laravel-swap
v1.3.0 docs doesn't contain any info about currency_converter
service but its dependency florianv/exchanger
v1.3.0 includes this service). Thus, this issue is not critical right now
dependency tree:
florianv/laravel-swap
: ~1.0 (1.3.0 installed, v1.3.0 is the latest available)
I know, it's not a laravel-swap package repo, but this issue should be fixed on this repo (IMO).
Stacktrace
RuntimeException: The service "currency_converter" does not exist. in ../vendor/florianv/laravel-swap/src/SwapServiceProvider.php:105
Stack trace:
#0 ../vendor/florianv/laravel-swap/src/SwapServiceProvider.php(128): Swap\Laravel\SwapServiceProvider->registerServices(Object(Illuminate\Foundation\Application))
#1 ../vendor/laravel/framework/src/Illuminate/Container/Container.php(776): Swap\Laravel\SwapServiceProvider->Swap\Laravel\{closure}(Object(Illuminate\Foundation\Application), Array)
...
Cause of the problem
There is a getServiceClass
method from the laravel-swap package https://github.com/florianv/laravel-swap/blob/1.3.0/src/SwapServiceProvider.php#L201-L210 that trying to find a class using its alias. This method can't resolve the classname because alias is currency_converter
but classname is CurrencyConverterApi
Solution(s)
- Easy/quick-fix and (almost)non-breaking: Rename
CurrencyConverterApi
toCurrencyConverter
sogetServiceClass()
will be able to resolve class - Easy and breaking: rename
currency_converter
tocurrency_converter_api
- Comprehensive: refactor alias to FQCN mapping to make it more flexible
- Ugly and 100% non-breaking: add a new
if
condition togetServiceClass()
I think 1st option is the best one because:
- I have enough time to fix it right now
- It's (almost)non-breaking (laravel-swap v1.3 doesn't contain docs about
CurrencyConverterApi
service)
Todo
- Add test contact to instantiate all available services by their aliases
- Try to find a time to refactor laravel-swap and symfony-swap to have more flexible way to add new services (and add custom services to ANY place in the chain (now it's possible to add them at the top of the chain (at least for laravel-swap)))
I am closing the issue since the PR was merged in the master branch (will be released soon).
Thanks for your work @lptn 👍