forked from setola/Wordpress-Theme-Utils-Classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneratorDictionary.class.php
76 lines (69 loc) · 1.54 KB
/
GeneratorDictionary.class.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Stores GeneratorDictionary class definitions
*/
/**
* Maintans a set of words for a sentences generator
* @author etessore
* @version 1.0.0
* @package classes
* @todo maintain an ordinate array so that
* insertion and deletion will be more efficent
*/
class GeneratorDictionary{
/**
* @var array a list of usable words
*/
private $words;
/**
* @var int the number of usable words
*/
private $count;
/**
* Initializes the dictionary
*/
public function __construct(){
$this->count = 0;
$this
->add_word('lorem')
->add_word('ipsum');
}
/**
* Adds the given $word to the current set
* @param string $word the word
* @return GeneratorDictionary $this for chainability
*/
public function add_word($word){
$this->words[] = $word;
$this->count++;
return $this;
}
/**
* Removes the given words from the current set
* @param string $word the word
* @return GeneratorDictionary $this for chainability
*/
public function remove_word($word){
foreach($this->words as $k => $v){
if($v==$word){
unset($this->words[$k]);
$this->count--;
}
}
return $this;
}
/**
* Retrieves all the usable words of this dictionary
* @return the full set of words
*/
public function get_all_words(){
return $this->words;
}
/**
* Retrieves the number of usable words in this dictionary
* @return the number of words in the current dictionary
*/
public function number_of_words(){
return $this->count;
}
}