Drupal 8  8.0.2
Random Class Reference

Public Member Functions

 string ($length=8, $unique=FALSE, $validator=NULL)
 
 name ($length=8, $unique=FALSE)
 
 word ($length)
 
 object ($size=4)
 
 sentences ($min_word_count, $capitalize=FALSE)
 
 paragraphs ($paragraph_count=12)
 
 image ($destination, $min_resolution, $max_resolution)
 

Data Fields

const MAXIMUM_TRIES = 100
 

Protected Attributes

 $strings = array()
 
 $names = array()
 

Detailed Description

Defines a utility class for creating random data.

Member Function Documentation

image (   $destination,
  $min_resolution,
  $max_resolution 
)

Create a placeholder image.

Parameters
string$destinationThe absolute file path where the image should be stored.
int$min_resolution
int$max_resolution
Returns
string Path to image file.
name (   $length = 8,
  $unique = FALSE 
)

Generates a random string containing letters and numbers.

The string will always start with a letter. The letters may be upper or lower case. This method is better for restricted inputs that do not accept certain characters. For example, when testing input fields that require machine readable values (i.e. without spaces and non-standard characters) this method is best.

Parameters
int$lengthLength of random string to generate.
bool$unique(optional) If TRUE ensures that the random string returned is unique. Defaults to FALSE.
Returns
string Randomly generated string.
See Also
::string()

Referenced by Random\object().

Here is the caller graph for this function:

object (   $size = 4)

Generates a random PHP object.

Parameters
int$sizeThe number of random keys to add to the object.
Returns
The generated object, with the specified number of random keys. Each key has a random string value.

References Random\name(), and Random\string().

Here is the call graph for this function:

paragraphs (   $paragraph_count = 12)

Generate paragraphs separated by double new line.

Parameters
int$paragraph_count
Returns
string
sentences (   $min_word_count,
  $capitalize = FALSE 
)

Generates sentences Latin words, often used as placeholder text.

Parameters
int$min_word_countThe minimum number of words in the return string. Total word count can slightly exceed provided this value in order to deliver sentences of random length.
bool$capitalizeUppercase all the words in the string.
Returns
string Nonsense latin words which form sentence(s).
string (   $length = 8,
  $unique = FALSE,
  $validator = NULL 
)

Generates a random string of ASCII characters of codes 32 to 126.

The generated string includes alpha-numeric characters and common miscellaneous characters. Use this method when testing general input where the content is not restricted.

Parameters
int$lengthLength of random string to generate.
bool$unique(optional) If TRUE ensures that the random string returned is unique. Defaults to FALSE.
callable$validator(optional) A callable to validate the string. Defaults to NULL.
Returns
string Randomly generated string.
See Also
::name()

Referenced by Random\object().

Here is the caller graph for this function:

word (   $length)

Generate a string that looks like a word (letters only, alternating consonants and vowels).

Parameters
int$lengthThe desired word length.
Returns
string

Field Documentation

const MAXIMUM_TRIES = 100

The maximum number of times name() and string() can loop.

This prevents infinite loops if the length of the random value is very small.

See Also

The documentation for this class was generated from the following file: