56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
namespace nur\b\text;
|
|
|
|
use nur\b\coll\IterableArray;
|
|
use nur\b\ValueException;
|
|
|
|
/**
|
|
* Class WordManager: un gestionnaire de mots
|
|
*
|
|
* Ce gestionnaire permet de stocker la configuration pour certains mots connus
|
|
*/
|
|
class WordManager extends IterableArray {
|
|
protected function WORDS(): array {
|
|
return static::WORDS;
|
|
} const WORDS = [
|
|
"service" => "le service#s",
|
|
"direction" => "la direction#s",
|
|
];
|
|
|
|
protected function ADJECTIVES(): array {
|
|
return static::ADJECTIVES;
|
|
} const ADJECTIVES = [
|
|
"ne" => "né#e"
|
|
];
|
|
|
|
function __construct() {
|
|
$words = [];
|
|
$i = 0;
|
|
foreach ($this->WORDS() as $key => $word) {
|
|
$word = new Word($word);
|
|
if ($key === $i) $words[] = $word;
|
|
else $words[$key] = $word;
|
|
$i++;
|
|
}
|
|
$i = 0;
|
|
foreach ($this->ADJECTIVES() as $key => $adjective) {
|
|
$word = new Word($adjective, true);
|
|
if ($key === $i) $words[] = $word;
|
|
else $words[$key] = $word;
|
|
$i++;
|
|
}
|
|
parent::__construct($words);
|
|
}
|
|
|
|
# ArrayAccess
|
|
function has(string $key): bool { return $this->_has($key); }
|
|
function get(string $key): Word {
|
|
return ValueException::check_nn($this->_get($key), "$key: unknown word");
|
|
}
|
|
function set(string $key, Word $value): self { return $this->_set($key, $value); }
|
|
function del(string $key): self { return $this->_del($key); }
|
|
# Iterator
|
|
function key(): string { return $this->_key(); }
|
|
function current(): Word { return $this->_current(); }
|
|
}
|