Returns a constant.

@param string|PhpConstant $nameOrConstant
@throws \InvalidArgumentException If the constant cannot be found
@return PhpConstant
3961
public function getConstant($nameOrConstant): PhpConstant {
		if ($nameOrConstant instanceof PhpConstant) {
			$nameOrConstant = $nameOrConstant->getName();
		}

		if (!$this->constants->has($nameOrConstant)) {
			throw new \InvalidArgumentException(sprintf('The constant "%s" does not exist.', $nameOrConstant));
		}

		return $this->constants->get($nameOrConstant);
	}
1061112
public static function getConstantsAnnotations($className, $annotationClassName = null)
    {
        if(null === $annotationClassName)
        {
            return static::$annotations[$className]['Constants'] ?? [];
        }
        $result = [];
        foreach(static::$annotations[$className]['Constants'] ?? [] as $constantName => $annotations)
        {
            foreach($annotations as $annotation)
            {
                if($annotation instanceof $annotationClassName)
                {
                    $result[$constantName][] = $annotation;
                }
            }
        }
        return $result;
    }
538586
public function offsetGet($name)
    {
        if (!$this->offsetExists($name)) {
            throw new \InvalidArgumentException(sprintf('Fact "%s" is not defined.', $name));
        }

        $value = $this->values[$name];

        // If the value is already frozen, or if it's not callable, or if it's protected, return the raw value
        if (isset($this->frozen[$name]) || !is_object($value) || $this->protected->contains($value) || !$this->isCallable($value)) {
            return $value;
        }

        // If this is a shared value, resolve, freeze, and return the result
        if ($this->shared->contains($value)) {
            $this->frozen[$name] = true;
            $this->raw[$name]    = $value;

            return $this->values[$name] = $value($this);
        }

        // Otherwise, resolve and return the result
        return $value($this);
    }
811347
protected function normalizeAction($action)
    {
        $constantName = 'static::' . str_replace(' ', '_', strtoupper(trim($action)));
        if (!defined($constantName)) {
            throw new \InvalidArgumentException('Unknown action passed: ' . $action);
        }

        return constant($constantName);
    }
1130018
public function getRule($name)
    {
        if ($this->hasRule($name)) {
            return $this->rules[$name];
        }

        throw new \InvalidArgumentException(sprintf('No rule with name "%s" could be found', $name));
    }
732710
public static function consts($name)
    {
        $name = strtoupper($name) . '_';
        $constants = [];
        foreach ((new \ReflectionClass(static::class))->getConstants() as $cName => $cValue) {
            if (strpos($cName, $name) === 0) {
                $constants[$cValue] = strtolower(substr($cName, strlen($name)));
            }
        }

        if (!$constants) {
            throw new MisuseException(['starts with `:1` constants is not exists in `:2` model', $name, static::class]);
        }

        return $constants;
    }
256695
public function getConst($name, $sanitize = null)
    {
        return $this->sanitize(ArrayHelper::getValue(static::$constants, $name), $sanitize);
    }
517448
public function getEnvironment($name)
    {
        if (isset($this->environments[$name])) {
            return $this->environments[$name];
        }

        // check the environment exists
        if (!$this->getConfig()->hasEnvironment($name)) {
            throw new \InvalidArgumentException(sprintf(
                'The environment "%s" does not exist',
                $name
            ));
        }

        // create an environment instance and cache it
        $envOptions = $this->getConfig()->getEnvironment($name);
        $envOptions['version_order'] = $this->getConfig()->getVersionOrder();

        $environment = new Environment($name, $envOptions);
        $this->environments[$name] = $environment;
        $environment->setInput($this->getInput());
        $environment->setOutput($this->getOutput());

        return $environment;
    }
882381
private static function createNamedInstance(string $name)
    {
        $class = self::findParentClassForConst($name);

        $key = self::getConstKey($class, $name);

        if (!array_key_exists($key, self::$instances)) {
            self::$instances[$key] = new static($name);
        }

        return self::$instances[$key];
    }
213228
public function add($constant)
    {
        if (!$constant instanceof ConstantInterface) {
            throw new \InvalidArgumentException(
                'This Constant must be a instance of \ClassGeneration\ConstantInterface'
            );
        }

        if ($constant->getName() === null) {
            $constant->setName('constant' . ($this->count() + 1));
        }

        return parent::add($constant);
    }
145715
public function getProperty($nameOrProperty): PhpProperty {
		if ($nameOrProperty instanceof PhpProperty) {
			$nameOrProperty = $nameOrProperty->getName();
		}

		if (!$this->properties->has($nameOrProperty)) {
			throw new \InvalidArgumentException(sprintf('The property "%s" does not exist.', $nameOrProperty));
		}

		return $this->properties->get($nameOrProperty);
	}
325808
public static function getConstantByName($name)
    {
        switch (strtolower($name)) {
            case 'single':
                return self::SINGLE;
            break;

            case 'multiple':
                return self::MULTIPLE;
            break;

            case 'ordered':
                return self::ORDERED;
            break;

            case 'record':
                return self::RECORD;
            break;

            default:
                return false;
            break;
        }
    }
912889
public function getConstantDefinition($name) {
		if (isset($this->constantsDef[$name])) {
			return $this->constantsDef[$name];
		} else {
			return null;
		}
	}
669289
public static function getConstantByName($name)
    {
        switch (strtolower($name)) {
            case 'author':
                return self::AUTHOR;
            break;

            case 'candidate':
                return self::CANDIDATE;
            break;

            case 'proctor':
                return self::PROCTOR;
            break;

            case 'scorer':
                return self::SCORER;
            break;

            case 'testconstructor':
                return self::TEST_CONSTRUCTOR;
            break;

            case 'tutor':
                return self::TUTOR;
            break;

            default:
                return false;
            break;
        }
    }
712003
protected function buildConstant(ClassConstant $constant, $indent)
    {
        $source = 'const '.$constant->getName();

        $value = $this->wrapPHPValue([
            'default' => $constant->getValue(),
        ]);

        $docBlock = new DocBlock($constant->getDocBlock(), $indent);

        return $docBlock."\n".$indent.$source.' = '.$value.';';
    }
751382
public function getConstant($constantName)
    {
        if (!\is_string($constantName)) {
            throw new InvalidArgumentException('$constantName must be string type');
        }

        if (empty($constantName)) {
            throw new InvalidArgumentException('$constantName must not be empty: '.$constantName);
        }

        if (isset($this->constants[$constantName])) {
            return $this->constants[$constantName];
        }

        $extendsClassDefinition = $this->getExtendsClassDefinition();
        if ($extendsClassDefinition) {
            if ($extendsClassDefinition->hasConstant($constantName)) {
                return $extendsClassDefinition->getConstant($constantName);
            }
        }

        /*
         * Gets constant from interfaces
         */
        return $this->getConstantFromInterfaces($constantName);
    }
242910
private function filterConstant($name) {
        $name = str_replace(' ', '_', $name);
        $name = preg_replace_callback(
            '@[A-Z][a-z]@',
            function ($matches) {
                return '_' . $matches[0];
            },
            $name
        );


        $name = str_replace(
            array(
                '/',
                '-',
                ',',
                '|',
                "\t"
            ),
            array(
                '_SLASH_',
                '_DASH_',
                '_COMMA_',
                '_PIPE_',
                '_TAB_'
            ),
            $name
        );
        $name = trim($name, '_');
        $name = preg_replace('@_+@', '_', $name);
        $name = preg_replace('@[^a-zA-Z0-9_]@', '', $name); //Strip out bad characters
        $name = strtoupper($name);
        if(is_numeric($name)) {
            $name = 'VALUE_'.$name;
        }
        return $name;
    }