mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-18 22:39:47 +01:00
Modify documentor to document arguments
This commit is contained in:
parent
c7bdada5d1
commit
70fb097d6b
121
readme.md
121
readme.md
@ -57,83 +57,84 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
|
||||
|
||||
### `Faker\Provider\DateTime`
|
||||
|
||||
amPm() // 'am'
|
||||
century() // 'V'
|
||||
date() // '2008-11-27'
|
||||
dateTime() // 2005-08-16 20:39:21
|
||||
dateTimeBetween() // 1999-02-02 11:42:52
|
||||
dateTimeThisCentury() // 1964-04-04 11:02:02
|
||||
dateTimeThisDecade() // 2010-03-10 05:18:58
|
||||
dateTimeThisMonth() // 2011-10-05 12:51:46
|
||||
dateTimeThisYear() // 2011-09-19 09:24:37
|
||||
dayOfMonth() // '29'
|
||||
dayOfWeek() // 'Thursday'
|
||||
iso8601() // '2003-10-21T16:05:52+0000'
|
||||
month() // '06'
|
||||
monthName() // 'November'
|
||||
time() // '15:02:34'
|
||||
unixTime() // 1061306726
|
||||
year() // '1991'
|
||||
|
||||
amPm // 'am'
|
||||
century // 'V'
|
||||
date($format = 'Y-m-d') // '2008-11-27'
|
||||
dateTime // 2005-08-16 20:58:39
|
||||
dateTimeBetween($startDate = '-30 years', $endDate = 'now') // 1999-02-02 12:05:31
|
||||
dateTimeThisCentury // 1964-04-04 11:24:41
|
||||
dateTimeThisDecade // 2010-03-10 05:41:37
|
||||
dateTimeThisMonth // 2011-10-05 13:14:25
|
||||
dateTimeThisYear // 2011-09-19 09:47:16
|
||||
dayOfMonth // '29'
|
||||
dayOfWeek // 'Thursday'
|
||||
iso8601 // '2003-10-21T16:24:11+0000'
|
||||
month // '06'
|
||||
monthName // 'November'
|
||||
time($format = 'H:i:s') // '15:17:03'
|
||||
unixTime // 1061307820
|
||||
year // '1991'
|
||||
|
||||
### `Faker\Provider\Internet`
|
||||
|
||||
domainName() // 'mueller.info'
|
||||
domainWord() // 'von'
|
||||
email() // 'cshields@rosenbaum.com'
|
||||
freeEmail() // 'dayna55@gmail.com'
|
||||
freeEmailDomain() // 'yahoo.com'
|
||||
ipv4() // '237.149.115.38'
|
||||
ipv6() // '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
|
||||
safeEmail() // 'nbatz@example.org'
|
||||
tld() // 'info'
|
||||
url() // 'http://www.runolfsdottir.com/'
|
||||
userName() // 'tremblay.haylie'
|
||||
domainName // 'mueller.info'
|
||||
domainWord // 'von'
|
||||
email // 'cshields@rosenbaum.com'
|
||||
freeEmail // 'dayna55@gmail.com'
|
||||
freeEmailDomain // 'yahoo.com'
|
||||
ipv4 // '237.149.115.38'
|
||||
ipv6 // '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
|
||||
safeEmail // 'nbatz@example.org'
|
||||
tld // 'info'
|
||||
url // 'http://www.runolfsdottir.com/'
|
||||
userName // 'tremblay.haylie'
|
||||
|
||||
### `Faker\Provider\Lorem`
|
||||
|
||||
lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...)'
|
||||
paragraph() // 'Sed a nam et sint autem. Aut officia aut. Blanditiis et ducimus.'
|
||||
paragraphs() // array('Amet et est. (...)', 'Sequi cum culpa rem. Rerum exercitationem est.')
|
||||
sentence() // 'Sit vitae voluptas sint non.'
|
||||
sentences() // array('Ut optio quos qui illo error nihil.', 'Vero a officia id corporis incidunt.', 'Provident esse hic eligendi quos culpa ut.')
|
||||
word() // 'aut'
|
||||
words() // array('porro', 'sed', 'magni')
|
||||
lorem($nbParagraphs = 3) // 'Fuga totam reiciendis qui architecto fugiat. (...)'
|
||||
paragraph($nbSentences = 3) // 'Sed a nam et sint autem. Aut officia aut. Blanditiis et ducimus.'
|
||||
paragraphs($nb = 3) // array('Amet et est. (...)', 'Sequi cum culpa rem. Rerum exercitationem est.')
|
||||
sentence($nbWords = 3) // 'Sit vitae voluptas sint non.'
|
||||
sentences($nb = 3) // array('Ut optio quos qui illo error nihil.', 'Vero a officia id corporis incidunt.', 'Provident esse hic eligendi quos culpa ut.')
|
||||
word // 'aut'
|
||||
words($nb = 3) // array('porro', 'sed', 'magni')
|
||||
|
||||
### `Faker\Provider\en_US\Address`
|
||||
|
||||
address() // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
|
||||
buildingNumber() // '484'
|
||||
city() // 'West Judge'
|
||||
cityPrefix() // 'Lake'
|
||||
citySuffix() // 'borough'
|
||||
country() // 'Falkland Islands (Malvinas)'
|
||||
postcode() // '17916'
|
||||
secondaryAddress() // 'Suite 961'
|
||||
state() // 'NewMexico'
|
||||
stateAbbr() // 'OH'
|
||||
streetAddress() // '439 Karley Loaf Suite 897'
|
||||
streetName() // 'Keegan Trail'
|
||||
streetSuffix() // 'Keys'
|
||||
address // '8888 Cummings Vista Apt. 101
|
||||
Susanbury, NY 95473'
|
||||
buildingNumber // '484'
|
||||
city // 'West Judge'
|
||||
cityPrefix // 'Lake'
|
||||
citySuffix // 'borough'
|
||||
country // 'Falkland Islands (Malvinas)'
|
||||
postcode // '17916'
|
||||
secondaryAddress // 'Suite 961'
|
||||
state // 'NewMexico'
|
||||
stateAbbr // 'OH'
|
||||
streetAddress // '439 Karley Loaf Suite 897'
|
||||
streetName // 'Keegan Trail'
|
||||
streetSuffix // 'Keys'
|
||||
|
||||
### `Faker\Provider\en_US\Company`
|
||||
|
||||
bs() // 'e-enable robust architectures'
|
||||
catchPhrase() // 'Monitored regional contingency'
|
||||
company() // 'Bogan-Treutel'
|
||||
companySuffix() // 'and Sons'
|
||||
bs // 'e-enable robust architectures'
|
||||
catchPhrase // 'Monitored regional contingency'
|
||||
company // 'Bogan-Treutel'
|
||||
companySuffix // 'and Sons'
|
||||
|
||||
### `Faker\Provider\en_US\Name`
|
||||
|
||||
firstName() // 'Maynard'
|
||||
lastName() // 'Zulauf'
|
||||
name() // 'Dr. Zane Stroman'
|
||||
prefix() // 'Ms.'
|
||||
suffix() // 'Jr.'
|
||||
firstName // 'Maynard'
|
||||
lastName // 'Zulauf'
|
||||
name // 'Dr. Zane Stroman'
|
||||
prefix // 'Ms.'
|
||||
suffix // 'Jr.'
|
||||
|
||||
### `Faker\Provider\en_US\PhoneNumber`
|
||||
|
||||
phoneNumber() // '132-149-0269x3767'
|
||||
|
||||
phoneNumber // '132-149-0269x3767'
|
||||
|
||||
## Localization
|
||||
|
||||
`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale.
|
||||
|
@ -23,6 +23,15 @@ class Documentor
|
||||
if ($methodName == '__construct') {
|
||||
continue;
|
||||
}
|
||||
$parameters = array();
|
||||
foreach ($reflmethod->getParameters() as $reflparameter) {
|
||||
$parameter = '$'. $reflparameter->getName();
|
||||
if ($reflparameter->isDefaultValueAvailable()) {
|
||||
$parameter .= ' = ' . var_export($reflparameter->getDefaultValue(), true);
|
||||
}
|
||||
$parameters []= $parameter;
|
||||
}
|
||||
$parameters = $parameters ? '('. join(', ', $parameters) . ')' : '';
|
||||
$example = $this->generator->format($methodName);
|
||||
if (is_array($example)) {
|
||||
$example = "array('". join("', '", $example) . "')";
|
||||
@ -31,7 +40,7 @@ class Documentor
|
||||
} elseif (is_string($example)) {
|
||||
$example = var_export($example, true);
|
||||
}
|
||||
$formatters[$providerClass][$methodName] = $example;
|
||||
$formatters[$providerClass][$methodName . $parameters] = $example;
|
||||
}
|
||||
ksort($formatters[$providerClass]);
|
||||
}
|
||||
|
@ -8,31 +8,51 @@ class DateTime extends \Faker\Provider\Base
|
||||
{
|
||||
protected static $century = array('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI','XVII','XVIII','XIX','XX','XX1');
|
||||
|
||||
/**
|
||||
* @example 1061306726
|
||||
*/
|
||||
public static function unixTime()
|
||||
{
|
||||
return mt_rand(0, time());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @example DateTime('2005-08-16 20:39:21')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTime()
|
||||
{
|
||||
return new \DateTime('@' . static::unixTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '2003-10-21T16:05:52+0000'
|
||||
*/
|
||||
public static function iso8601()
|
||||
{
|
||||
return static::date(\DateTime::ISO8601);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @example '2008-11-27'
|
||||
*/
|
||||
public static function date($format = 'Y-m-d')
|
||||
{
|
||||
return static::dateTime()->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '15:02:34'
|
||||
*/
|
||||
public static function time($format = 'H:i:s')
|
||||
{
|
||||
return static::dateTime()->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example DateTime('1999-02-02 11:42:52')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTimeBetween($startDate = "-30 years", $endDate = "now")
|
||||
{
|
||||
$startTimestamp = strtotime($startDate);
|
||||
@ -41,57 +61,94 @@ class DateTime extends \Faker\Provider\Base
|
||||
|
||||
return new \DateTime('@' . $timestamp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @example DateTime('1964-04-04 11:02:02')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTimeThisCentury()
|
||||
{
|
||||
return static::dateTimeBetween("-100 year");
|
||||
}
|
||||
|
||||
/**
|
||||
* @example DateTime('2010-03-10 05:18:58')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTimeThisDecade()
|
||||
{
|
||||
return static::dateTimeBetween("-10 year");
|
||||
}
|
||||
|
||||
/**
|
||||
* @example DateTime('2011-09-19 09:24:37')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTimeThisYear()
|
||||
{
|
||||
return static::dateTimeBetween("-1 year");
|
||||
}
|
||||
|
||||
/**
|
||||
* @example DateTime('2011-10-05 12:51:46')
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function dateTimeThisMonth()
|
||||
{
|
||||
return static::dateTimeBetween("-1 month");
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'am'
|
||||
*/
|
||||
public static function amPm()
|
||||
{
|
||||
return static::dateTime()->format('a');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '22'
|
||||
*/
|
||||
public static function dayOfMonth()
|
||||
{
|
||||
return static::dateTime()->format('d');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'Tuesday'
|
||||
*/
|
||||
public static function dayOfWeek()
|
||||
{
|
||||
return static::dateTime()->format('l');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '7'
|
||||
*/
|
||||
public static function month()
|
||||
{
|
||||
return static::dateTime()->format('m');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'September'
|
||||
*/
|
||||
public static function monthName()
|
||||
{
|
||||
return static::dateTime()->format('F');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 1673
|
||||
*/
|
||||
public static function year()
|
||||
{
|
||||
return static::dateTime()->format('Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'XVII'
|
||||
*/
|
||||
public static function century()
|
||||
{
|
||||
return static::randomElement(static::$century);
|
||||
|
@ -11,6 +11,6 @@ $documentor = new Faker\Documentor($generator);
|
||||
### `<?php echo $provider ?>`
|
||||
|
||||
<?php foreach ($formatters as $formatter => $example): ?>
|
||||
<?php echo str_pad($formatter . '()', 20) ?><?php if ($example): ?> // <?php echo $example ?> <?php endif; ?>
|
||||
<?php echo str_pad($formatter, 23) ?><?php if ($example): ?> // <?php echo $example ?> <?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user