Chris@0: class = $class; Chris@0: $this->name = $name; Chris@0: Chris@0: $constants = $class->getConstants(); Chris@0: if (!array_key_exists($name, $constants)) { Chris@0: throw new \InvalidArgumentException('Unknown constant: ' . $name); Chris@0: } Chris@0: Chris@0: $this->value = $constants[$name]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the declaring class. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getDeclaringClass() Chris@0: { Chris@0: $parent = $this->class; Chris@0: Chris@0: // Since we don't have real reflection constants, we can't see where Chris@0: // it's actually defined. Let's check for a constant that is also Chris@0: // available on the parent class which has exactly the same value. Chris@0: // Chris@0: // While this isn't _technically_ correct, it's prolly close enough. Chris@0: do { Chris@0: $class = $parent; Chris@0: $parent = $class->getParentClass(); Chris@0: } while ($parent && $parent->hasConstant($this->name) && $parent->getConstant($this->name) === $this->value); Chris@0: Chris@0: return $class; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the constant name. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return $this->name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the value of the constant. Chris@0: * Chris@0: * @return mixed Chris@0: */ Chris@0: public function getValue() Chris@0: { Chris@0: return $this->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the constant's file name. Chris@0: * Chris@0: * Currently returns null, because if it returns a file name the signature Chris@0: * formatter will barf. Chris@0: */ Chris@0: public function getFileName() Chris@0: { Chris@0: return; Chris@0: // return $this->class->getFileName(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the code start line. Chris@0: * Chris@0: * @throws \RuntimeException Chris@0: */ Chris@0: public function getStartLine() Chris@0: { Chris@0: throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the code end line. Chris@0: * Chris@0: * @throws \RuntimeException Chris@0: */ Chris@0: public function getEndLine() Chris@0: { Chris@0: return $this->getStartLine(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Get the constant's docblock. Chris@0: * Chris@0: * @return false Chris@0: */ Chris@0: public function getDocComment() Chris@0: { Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Export the constant? I don't think this is possible. Chris@0: * Chris@0: * @throws \RuntimeException Chris@0: */ Chris@0: public static function export() Chris@0: { Chris@0: throw new \RuntimeException('Not yet implemented because it\'s unclear what I should do here :)'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * To string. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function __toString() Chris@0: { Chris@0: return $this->getName(); Chris@0: } Chris@0: }