1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11: namespace expect\registry;
12:
13: use expect\Dictionary;
14: use expect\MatcherDictionary;
15: use expect\MatcherLookupTable;
16: use expect\MatcherRegistry;
17: use expect\package\MatcherClass;
18:
19: final class DefaultMatcherRegistry implements MatcherRegistry
20: {
21: use MatcherLookupTable;
22:
23: public function __construct(array $matchers = [])
24: {
25: $this->matchers = Dictionary::fromArray($matchers);
26: }
27:
28: public function register(MatcherClass $matcherClass)
29: {
30: $name = $matcherClass->getClassName();
31: $registerKeyName = lcfirst($name);
32:
33: if ($this->has($registerKeyName)) {
34: throw new MatcherAlreadyRegisteredException("{$registerKeyName} is registered");
35: }
36:
37: $this->matchers->set($registerKeyName, $matcherClass);
38: }
39:
40: public function count()
41: {
42: return count($this->matchers);
43: }
44:
45: public function toDictionary()
46: {
47: $matchers = $this->matchers->toArray();
48:
49: return new MatcherDictionary($matchers);
50: }
51: }
52: