blob: d044c74fd7356287bcdc28380628a622c4a90c04 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
namespace Nubs\RandomNameGenerator;
use Cinam\Randomizer\Randomizer;
/**
* A generator that uses all of the other generators randomly.
*/
class All extends AbstractGenerator implements Generator
{
/** @type array The other generators to use. */
protected $_generators;
/** @type Cinam\Randomizer\Randomizer The random number generator. */
protected $_randomizer;
/**
* Initializes the All Generator with the list of generators to choose from.
*
* @api
* @param array $generators The random generators to use.
* @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
*/
public function __construct(array $generators, Randomizer $randomizer = null)
{
$this->_generators = $generators;
$this->_randomizer = $randomizer;
}
/**
* Constructs an All Generator using the default list of generators.
*
* @api
* @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
* @return \Nubs\RandomNameGenerator\All The constructed generator.
*/
public static function create(Randomizer $randomizer = null)
{
return new self([new Alliteration($randomizer), new Vgng($randomizer)], $randomizer);
}
/**
* Gets a randomly generated name using the configured generators.
*
* @api
* @return string A random name.
*/
public function getName()
{
return $this->_getRandomGenerator()->getName();
}
/**
* Get a random generator from the list of generators.
*
* @return \Nubs\RandomNameGenerator\Generator A random generator.
*/
protected function _getRandomGenerator()
{
return $this->_randomizer ? $this->_randomizer->getArrayValue($this->_generators) : $this->_generators[array_rand($this->_generators)];
}
}
|