1 | <?php |
||
11 | class Vgng extends AbstractGenerator implements Generator |
||
12 | { |
||
13 | /** @type array The definition of the potential names. */ |
||
14 | protected $_definitionSets; |
||
15 | |||
16 | /** @type Cinam\Randomizer\Randomizer The random number generator. */ |
||
17 | protected $_randomizer; |
||
18 | |||
19 | /** |
||
20 | * Initializes the Video Game Name Generator from the default word list. |
||
21 | * |
||
22 | * @api |
||
23 | * @param \Cinam\Randomizer\Randomizer $randomizer The random number generator. |
||
24 | */ |
||
25 | public function __construct(Randomizer $randomizer = null) |
||
33 | |||
34 | /** |
||
35 | * Gets a randomly generated video game name. |
||
36 | * |
||
37 | * @api |
||
38 | * @return string A random video game name. |
||
39 | */ |
||
40 | public function getName() |
||
54 | |||
55 | /** |
||
56 | * Get a definition from the definitions that does not exist already. |
||
57 | * |
||
58 | * @param array $definitions The word list to pick from. |
||
59 | * @param array $existingWords The already-chosen words to avoid. |
||
60 | * @return array The definition of a previously unchosen word. |
||
61 | */ |
||
62 | protected function _getUniqueWord(array $definitions, array $existingWords) |
||
72 | |||
73 | /** |
||
74 | * Gets the file contents of the video_game_names.txt file. |
||
75 | * |
||
76 | * @return string The video_game_names.txt contents. |
||
77 | */ |
||
78 | protected function _getFileContents() |
||
82 | |||
83 | /** |
||
84 | * Separates the contents into each of the word list sections. |
||
85 | * |
||
86 | * This builder operates by picking a random word from each of a consecutive |
||
87 | * list of word lists. These separate lists are separated by a line |
||
88 | * consisting of four hyphens in the file. |
||
89 | * |
||
90 | * @param string $contents The file contents. |
||
91 | * @return array Each section split into its own string. |
||
92 | */ |
||
93 | protected function _getSections($contents) |
||
97 | |||
98 | /** |
||
99 | * Parses the given section into the final definitions. |
||
100 | * |
||
101 | * @param string $section The newline-separated list of words in a section. |
||
102 | * @return array The parsed section into its final form. |
||
103 | */ |
||
104 | protected function _parseSection($section) |
||
111 | |||
112 | /** |
||
113 | * Gets the separate definitions from the given section. |
||
114 | * |
||
115 | * @param string $section The newline-separated list of words in a section. |
||
116 | * @return array Each word split out, but unparsed. |
||
117 | */ |
||
118 | protected function _getDefinitionsFromSection($section) |
||
122 | |||
123 | /** |
||
124 | * Parses a single definition into its component pieces. |
||
125 | * |
||
126 | * The format of a definition in a file is word[^similarWord|...]. |
||
127 | * |
||
128 | * @param string $definition The definition. |
||
129 | * @return array The formatted definition. |
||
130 | */ |
||
131 | protected function _parseDefinition($definition) |
||
138 | } |
||
139 |