1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-23 00:39:47 +01:00

Allow returning words/sentences/paragraphs as a single string

This commit is contained in:
Jordi Boggiano 2012-10-27 11:34:05 +02:00
parent 83fd81c0c0
commit ab50ccf28c

View File

@ -57,15 +57,16 @@ class Lorem extends \Faker\Provider\Base
*
* @example array('Lorem', 'ipsum', 'dolor')
* @param integer $nb how many words to return
* @return array
* @param bool $asText if true the sentences are returned as one string
* @return array|string
*/
public static function words($nb = 3)
public static function words($nb = 3, $asText = false)
{
$words = array();
for ($i=0; $i < $nb; $i++) {
$words []= static::word();
}
return $words;
return $asText ? join(' ', $words) : $words;
}
/**
@ -97,15 +98,16 @@ class Lorem extends \Faker\Provider\Base
*
* @example array('Lorem ipsum dolor sit amet.', 'Consectetur adipisicing eli.')
* @param integer $nb how many sentences to return
* @return array
* @param bool $asText if true the sentences are returned as one string
* @return array|string
*/
public static function sentences($nb = 3)
public static function sentences($nb = 3, $asText = false)
{
$sentences = array();
for ($i=0; $i < $nb; $i++) {
$sentences []= static::sentence();
}
return $sentences;
return $asText ? join(' ', $sentences) : $sentences;
}
/**
@ -134,15 +136,16 @@ class Lorem extends \Faker\Provider\Base
*
* @example array($paragraph1, $paragraph2, $paragraph3)
* @param integer $nb how many paragraphs to return
* @return array
* @param bool $asText if true the paragraphs are returned as one string, separated by two newlines
* @return array|string
*/
public static function paragraphs($nb = 3)
public static function paragraphs($nb = 3, $asText = false)
{
$paragraphs = array();
for ($i=0; $i < $nb; $i++) {
$paragraphs []= static::paragraph();
}
return $paragraphs;
return $asText ? join("\n\n", $paragraphs) : $paragraphs;
}
/**