32 public function getTypeToClassMap()
34 static $generatorTypeToClassMap = [];
35 if (empty($generatorTypeToClassMap))
38 Generator\SequentNumberGenerator::class,
39 Generator\DateNumberGenerator::class,
40 Generator\RandomNumberGenerator::class,
41 Generator\PrefixNumberGenerator::class,
43 $generatorClasses = array_merge_recursive($generatorClasses, $this->collectCustomGeneratorClasses());
45 foreach ($generatorClasses as $generatorClass)
48 $generatorTypeToClassMap[$generatorClass::getType()] = $generatorClass;
52 return $generatorTypeToClassMap;
58 private function collectCustomGeneratorClasses()
60 $event =
new Event(
'main', self::EVENT_GENERATOR_CLASSES_COLLECT);
62 $results = $event->getResults();
64 $generatorClasses = [];
65 foreach ($results as $result)
67 if ($result->getType() != EventResult::SUCCESS)
71 $className = $result->getParameters();
73 if (class_exists($className) && (is_subclass_of($className, Generator\NumberGenerator::class)))
75 $generatorClasses[] = $result->getParameters();
79 return $generatorClasses;
89 if (in_array($type, array_keys($this->getTypeToClassMap())))
91 return $this->getTypeToClassMap()[$type];
103 return array_values($this->getTypeToClassMap());
const EVENT_GENERATOR_CLASSES_COLLECT