value = (string) $value; if ($context) { $this->context = (string) $context; } } public function getValue() { return $this->value; } public function hasContext() { return $this->context !== null; } public function getContext() { return $this->context; } public function __toString() { return self::dump($this); } public static function parse($string) { preg_match(self::TERM_REGEX, $string, $matches); return new self( isset($matches[1]) ? $matches[1] : null, isset($matches[2]) ? $matches[2] : null ); } public static function dump(TermInterface $term) { if ($term->hasContext()) { return sprintf('"%s" context:"%s"', $term->getValue(), $term->getContext()); } return sprintf('"%s"', $term->getValue()); } }