Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NumberTransformerBuilder injectable #59

Open
dsentker opened this issue Jan 18, 2019 · 0 comments
Open

Make NumberTransformerBuilder injectable #59

dsentker opened this issue Jan 18, 2019 · 0 comments

Comments

@dsentker
Copy link

First, thank you for your work.

If you use one of the supplied transformers (for example, GermanCurrencyTransformer), there is no way to modify the NumberTransformerBuilder. In my case, I need to customize the "withWordsSeparatedBy()" method, but the rest should stay the same.

Perhaps the CurrencyTransformer interface could get a "getTransformerBuilder()" method so that I can override this method to provde a custom provider in a child class.

Here is a simple example:

class CustomizedGermanCurrencyTransformer extends GermanCurrencyTransformer {

    /**
     * Overrides the default transformer builder to modify builder options
     * 
     * @return \NumberToWords\NumberTransformer\NumberTransformer
     */
    public function getTransformerBuilder()
    {
        return $numberTransformer = (new NumberTransformerBuilder())
            ->withDictionary($dictionary)
            ->withWordsSeparatedBy('')
            ->transformNumbersBySplittingIntoPowerAwareTriplets($numberToTripletsConverter, $tripletTransformer)
            ->inflectExponentByNumbers($exponentInflector)
            ->build();
    }
    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant