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