* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Definitions implements DefinitionsInterface, \JsonSerializable { private $container; public function __construct() { $this->container = []; } /** * @inheritDoc */ public function addType(string $name, TypeInterface $type): void { [$ns, $alias] = TypeUtil::split($name); if (!isset($this->container[$ns])) { $this->container[$ns] = []; } if (isset($this->container[$ns][$alias])) { throw new \RuntimeException('Type "' . $name . '" already registered'); } $this->container[$ns][$alias] = $type; } /** * @inheritDoc */ public function hasType(string $name): bool { [$ns, $alias] = TypeUtil::split($name); return isset($this->container[$ns][$alias]); } /** * @inheritDoc */ public function getType(string $name): TypeInterface { [$ns, $alias] = TypeUtil::split($name); if (!isset($this->container[$ns])) { throw new TypeNotFoundException('Type namespace "' . $ns . '" not found, the following namespaces are available: ' . implode(', ', array_keys($this->container)), $ns, $alias); } if (!isset($this->container[$ns][$alias])) { throw new TypeNotFoundException('Type "' . $alias . '" not found, the following types are available: ' . implode(', ', array_keys($this->container[$ns])), $ns, $alias); } return $this->container[$ns][$alias]; } /** * @inheritDoc */ public function removeType(string $name): void { [$ns, $alias] = TypeUtil::split($name); if (isset($this->container[$ns][$alias])) { unset($this->container[$ns][$alias]); } } /** * @inheritDoc */ public function getTypes(string $namespace): iterable { if (isset($this->container[$namespace])) { return $this->container[$namespace]; } else { return []; } } /** * @inheritDoc */ public function getAllTypes(): iterable { $result = []; foreach ($this->container as $namespace => $types) { foreach ($types as $name => $type) { $result[$namespace . ':' . $name] = $type; } } return $result; } /** * @inheritDoc */ public function getNamespaces(): iterable { return array_keys($this->container); } /** * @inheritDoc */ public function merge(DefinitionsInterface $definitions): void { $namespaces = $definitions->getNamespaces(); foreach ($namespaces as $namespace) { $types = $definitions->getTypes($namespace); foreach ($types as $name => $type) { $fqn = $namespace . ':' . $name; if ($this->hasType($fqn)) { continue; } $this->addType($fqn, $type); } } } /** * @inheritDoc */ public function addSchema(string $name, SchemaInterface $schema): void { $this->merge($schema->getDefinitions()); if ($this->hasType($name)) { return; } $this->addType($name, $schema->getType()); } /** * @inheritDoc */ public function jsonSerialize() { return $this->getAllTypes(); } } __halt_compiler();----SIGNATURE:----E0ZHk6+P43Sqpq2huQ0S+NfbiwOMQnYlNRUed8xYK801IBvOuAnDCRTG86+qOcGbe9xPycl/IUUoYboOHaGlzo9mhlCtvNvb4eik4V6yAtW+ZXpOjPBih34BxhNp9syD1Inivonere7HFVrZ9yi5zJhvQZDwRSZBpIUtwuG+cRx1uujE+XLVrPqRcqWKjWkRXjgADN7TveRN/iHsPEilFV1laQrwxmePIjkmeyrt83qQORHnJLDkJM9su8TivTV4BzaAncDfS2Lr6jGvt1nKx3sQOhLNHd7KTtQhARdM3Mkym0ePM02lNXEFDU8YL6QHFHsosDL9yTEQYPzueIA8EzQfyU29giFzRVh3riPeS2/Lh/+LNmAwnr47z0GLNzwBLILq+zbo4QdL3pwXfNU//c7p/D6ng7aGf26oFtRpY3uedRQhWTuEAwNofLJLL8XSs8bKrM1HeCo6KGmREjUvErnOzYdxb+kKAVudJCgMhlCDmDgyRBTVd8j23nyKTc3r5lGa12EFM8lMRO/YZwHslOGNh9dKxOHLNMpiZnaGvzIFAkSmk8qIL5V89SlkgX73uNk7BIIK/umROteb0pdpxWt+1w5a1Dfejv+42ylnxR9vxJucAtKa2DBj90xGxoW6EX9aTxmZrYSSQLVmd2h3JTixFc+9uATiZXC3ZoOEnjA=----ATTACHMENT:----NDY0MTM1MDgxOTc2NjIzNiA5NzQ2NDgxMjA0NTMyOTQyIDI3NzA2NzE4MzcxNDQzODQ=