Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

added protected method Generator::findFormatter #2013

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,20 @@ public function getFormatter($formatter)
if (isset($this->formatters[$formatter])) {
return $this->formatters[$formatter];
}
$this->formatters[$formatter] = $this->findFormatter($formatter);
return $this->formatters[$formatter];
}

/**
* @param string $formatter
*
* @return Callable
*/
protected function findFormatter($formatter)
{
foreach ($this->providers as $provider) {
if (method_exists($provider, $formatter)) {
$this->formatters[$formatter] = array($provider, $formatter);

return $this->formatters[$formatter];
return array($provider, $formatter);
}
}
throw new \InvalidArgumentException(sprintf('Unknown formatter "%s"', $formatter));
Expand Down