/** * @param SchemaCurie $curie * @return SchemaQName */ public static function fromCurie(SchemaCurie $curie) { $qname = sprintf('%s:%s', $curie->getVendor(), $curie->getMessage()); if (isset(self::$instances[$qname])) { return self::$instances[$qname]; } self::$instances[$qname] = new self($curie->getVendor(), $curie->getMessage()); return self::$instances[$qname]; }
/** * @return string */ public function toString() { if (null !== $this->tag) { return $this->curie->toString() . ':' . $this->id . '#' . $this->tag; } return $this->curie->toString() . ':' . $this->id; }
/** * Returns the SchemaCurie for the given SchemaQName. * * @param SchemaQName $qname * @return SchemaCurie * * @throws NoMessageForQName */ public static function resolveQName(SchemaQName $qname) { $key = $qname->toString(); if (isset(self::$resolvedQnames[$key])) { return self::$resolvedQnames[$key]; } $qvendor = $qname->getVendor(); $qmessage = $qname->getMessage(); foreach (self::$messages as $id => $class) { list($vendor, $package, $category, $message) = explode(':', $id); if ($qvendor === $vendor && $qmessage === $message) { return self::$resolvedQnames[$key] = SchemaCurie::fromString($vendor . ':' . $package . ':' . $category . ':' . $message); } } throw new NoMessageForQName($qname); }
/** * @param mixed $value * @param Field $field * * @return MessageRef */ public function decodeMessageRef($value, Field $field) { return new MessageRef(SchemaCurie::fromString($value['curie']['S']), $value['id']['S'], isset($value['tag']['NULL']) ? null : $value['tag']['S']); }
/** * @return SchemaQName */ public function getQName() { return $this->curie->getQName(); }
/** * @param SchemaCurie $curie */ public function __construct(SchemaCurie $curie) { $this->curie = $curie; parent::__construct(sprintf('MessageResolver is unable to resolve [%s] to a class name.', $curie->toString())); }