forked from fzaninotto/Faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a documentor class to introspect generator capabilities
- Loading branch information
1 parent
9ed3a25
commit 264d755
Showing
12 changed files
with
145 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Faker; | ||
|
||
class Documentor | ||
{ | ||
protected $generator; | ||
|
||
public function __construct($generator) | ||
{ | ||
$this->generator = $generator; | ||
} | ||
|
||
public function getFormatters() | ||
{ | ||
$formatters = array(); | ||
foreach ($this->generator->getProviders() as $provider) { | ||
$providerClass = get_class($provider); | ||
$formatters[$providerClass] = array(); | ||
$refl = new \ReflectionObject($provider); | ||
foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflmethod) { | ||
if ($reflmethod->name == '__construct') { | ||
continue; | ||
} | ||
$comment = $reflmethod->getDocComment(); | ||
if (preg_match('/^\s+\*\s+@example\s+(.*)$/mi', $comment, $matches)) { | ||
$example = $matches[1]; | ||
} else { | ||
$example = ''; | ||
} | ||
$formatters[$providerClass][$reflmethod->name] = $example; | ||
} | ||
ksort($formatters[$providerClass]); | ||
} | ||
ksort($formatters); | ||
|
||
return $formatters; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
require_once __DIR__ . '/../src/Factory.php'; | ||
require_once __DIR__ . '/../src/Documentor.php'; | ||
|
||
$generator = Faker\Factory::create(); | ||
$documentor = new Faker\Documentor($generator); | ||
print_r($documentor->getFormatters()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ | |
<?php endif; ?> | ||
</contact> | ||
<?php endfor; ?> | ||
</contacts> | ||
</contacts> |