/**
* @param string $definition
* @param EntityReflection $reflection
* @throws InvalidAnnotationException
*/
public function __construct($definition, EntityReflection $reflection)
{
$matches = [];
preg_match('#^((?:\\\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)+|self|static|parent)::([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+)\\*$#', $definition, $matches);
if (empty($matches)) {
throw new InvalidAnnotationException("Invalid enumeration definition given: '{$definition}'.");
}
list(, $class, $prefix) = $matches;
if ($class === 'self' or $class === 'static') {
$constants = $reflection->getConstants();
} elseif ($class === 'parent') {
$constants = $reflection->getParentClass()->getConstants();
} else {
$aliases = $reflection->getAliases();
$reflectionClass = new ReflectionClass($aliases->translate($class));
$constants = $reflectionClass->getConstants();
}
foreach ($constants as $name => $value) {
if (substr($name, 0, strlen($prefix)) === $prefix) {
$this->values[$name] = $value;
$this->index[$value] = true;
}
}
}