Skip to content

Update the Generator::getFormatter to support extensions#267

Merged
pimjansen merged 4 commits intoFakerPHP:mainfrom
Nyholm:generator-formatter
Aug 8, 2021
Merged

Update the Generator::getFormatter to support extensions#267
pimjansen merged 4 commits intoFakerPHP:mainfrom
Nyholm:generator-formatter

Conversation

@Nyholm
Copy link
Copy Markdown
Member

@Nyholm Nyholm commented Jan 16, 2021

This will allow us to write:

$this->generator->parse('My blood type is {{'Faker\Core\Blood->bloodType'}}.');

Which is needed by extensions implementing GeneratorAwareExtension

* @return callable
*/
public function getFormatter($formatter)
public function getFormatter($format)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using a format to get a formatter.

return preg_replace_callback('/\{\{\s?(\w+)\s?\}\}/u', [$this, 'callFormatWithMatches'], $string);
$callback = function ($matches) {
return $this->format($matches[1]);
};
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This anonymous function is replacing Generator::callFormatWithMatches()

@stale
Copy link
Copy Markdown

stale bot commented Feb 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions.

@Nyholm Nyholm force-pushed the generator-formatter branch from dc554f0 to 8bcf885 Compare August 8, 2021 02:13
Copy link
Copy Markdown

@pimjansen pimjansen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@pimjansen pimjansen merged commit cc07063 into FakerPHP:main Aug 8, 2021
@Nyholm
Copy link
Copy Markdown
Member Author

Nyholm commented Aug 8, 2021

Thank you for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants