aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/nubs/random-name-generator/src/All.php
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/nubs/random-name-generator/src/All.php
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/nubs/random-name-generator/src/All.php')
-rw-r--r--assets/php/vendor/nubs/random-name-generator/src/All.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/assets/php/vendor/nubs/random-name-generator/src/All.php b/assets/php/vendor/nubs/random-name-generator/src/All.php
new file mode 100644
index 0000000..d044c74
--- /dev/null
+++ b/assets/php/vendor/nubs/random-name-generator/src/All.php
@@ -0,0 +1,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)];
+ }
+}