robertogallea / laravel-codicefiscale

Codice fiscale validation for php/laravel
MIT License
42 stars 16 forks source link

Impossible to use MyCitiesList class when generate a codice fiscale #17

Closed paulmod closed 3 years ago

paulmod commented 3 years ago

Hi Roberto, thanks for your great job! I noticed that when I generate a codice fiscale, it always use the ItalianCitiesStaticList, instead of InternationalCitiesStaticList (used as default in CodiceFiscale constructor), or in my case, my own class. is it possible to fix this?

robertogallea commented 3 years ago

Hi Paolo! In v1.5, if you use the instance provided by the Service Container, the CtyDecoderInterface to use is set in the config, and by default is InternationalCitiesStaticList (or if not defined).

        $this->app->singleton(CodiceFiscale::class, function () {
            $decoder = config('codicefiscale.city-decoder');

            return new CodiceFiscale(
                new $decoder()
            );
        });

To change it you should just publish and edit the config. If you use your own instance of CodiceFiscale instead, you can provide your own CtyDecoderInterface instance.

However, if you defined a new general-purpose decoder class, why don't you consider make a PR and add it to the project?

I'll close the issue for now, by if you have further problems, feel free to reopen it.