* @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:----sRoHcBEvQoIhRZxOt/ZXK/aHqXCZkLOYd3tN03d0AwjLdDpnVeTJiLEfBo1pmFyDTcGCd6poqncOcppOoo/cN3cw/WmOfwR86y5VTaHZwDtUSE1ftCAjy1s7nLocPfcD5dHsC/1L/2OxDAIQHJZV1Vh1hxUtjquUrUfrsRmqKHhRuLSgUOdv8uj/4YEfYhqsFw99mwUkUgKq60tAdClY7k+D/6cQyOc3puJFTcA5jCA/xpneIRu30DZc/b3vtG2AneFQD/Un5V72hAEKOe3UaYloCvPmqdRLSCacO2sk4EEsmg+M24wzOD3EyVhoupAIueTUufIlW7KCBTNuZUedE295gvbxoGZFkZakru8eYUvcOkpaE95sIslFZrMX7brEkeih8mu6OXaoRE2hfeQE5B2oarlKep3BnlPQXNYWZgNbcrixa0X+Lfg6VYok5Da+/cFuK6hCIZdMjenWWXMfmB+XHunG2KLvZhwtOyb44aN7Hw6JurnquOTFKnRMtNlZWmr0BRs8kX6YM2o34gaIUvOtkm0ISEEcaWAyHkNDo2Ms5iSFynoVzVvTl7pewanSqmwBU1xZFLygS/YjUVgzTnybWBzExaL1CZedbJYoes8sVfnRFMrCRu7MHjr1WI6T7UseLHTcTG//fjd0QLek5+6v1d9Xya8IKw1/E+MYhWs=----ATTACHMENT:----NDg5NDA2NzY0Mjk0MjUwNiA0NjA2NTk3NzUyNzQ5NzYgNDU3MjcwNzExNDA3NDI5Nw==