* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Document implements \JsonSerializable { /** @var Type[] */ private $types; /** @var Import[] */ private $imports; private $root; public function __construct(array $types, ?array $imports = null, ?string $root = null) { $this->types = $this->convertTypes($types); $this->imports = $imports !== null ? $this->convertImports($imports) : []; $this->root = $root; } /** * @return Type[] */ public function getTypes(): array { return $this->types; } public function getType(int $index): ?Type { return $this->types[$index] ?? null; } public function indexOf(string $typeName): ?int { foreach ($this->types as $index => $type) { if ($type->getName() === $typeName) { return $index; } } return null; } public function getImports(): ?array { return $this->imports; } public function getImport(string $alias): ?Import { foreach ($this->imports as $import) { if ($import->getAlias() === $alias) { return $import; } } return null; } public function getRoot(): ?string { return $this->root; } public function jsonSerialize() { return [ 'imports' => $this->imports, 'types' => $this->types, 'root' => $this->root, ]; } private function convertTypes(array $types): array { $result = []; foreach ($types as $type) { if ($type instanceof \stdClass) { $result[] = new Type((array) $type); } elseif (is_array($type)) { $result[] = new Type($type); } } return $result; } private function convertImports(array $imports): array { $result = []; foreach ($imports as $import) { if ($import instanceof \stdClass) { $result[] = new Import((array) $import); } elseif (is_array($import)) { $result[] = new Import($import); } } return $result; } public static function from($document): self { if (is_string($document)) { $document = \json_decode($document); } if (is_array($document)) { if (isset($document['types'])) { return new self($document['types'] ?? [], $document['imports'] ?? [], $document['root'] ?? null); } else { return new self($document); } } elseif ($document instanceof \stdClass) { return new self($document->types ?? [], $document->imports ?? [], $document->root ?? null); } elseif ($document === null) { return new self([]); } else { throw new \InvalidArgumentException('Provided an invalid spec got: ' . (is_object($document) ? get_class($document) : gettype($document))); } } } __halt_compiler();----SIGNATURE:----QOuftQwODDF9ZAxBhSCspfjYAEXEh3ESyvnfoyrBTOyoLh//haUqJmllvcYrufQ9fZutV1iXcG1gIshdQcssEVutfH51DATcWKm6ST+Bgg0YqYG2cO2xLX0JjIc0a0Vi+h26UPqzr1P12cfnOz+ffz4oc28Y0SMINOFc+dpU6c/MuFDZWxu13iA5+4Ew8iZYEctOvOogYRP2CnV9nusBPan6bXHxEcWNxtSK1j2bakXWAltfFLetECzICjEKyIaKSynZxh/q6g3GXw1bK5Qly1ZodZ/JY0e07Xd9dmh1u6/Mo5jkdXxWxUs6xB2uT/JMfftnlC5w/cp93HHSETWjtZcmloub+8Z0HwZ0u5GnI8EzxhoX6GuV9HoZ7OIHNQ0I6ah/h9WtayViHDy1L+cH8zMhak8DEo8w01fnb9m+ZZZqF0JiiyQ6aTGG0JRxd8FmNdV3X7SjJ2czK6vHnHlCnrTUeXRfGvS87ocZt4xXfluPoL7hGLD3H+tVQswWeQksbscPRQ/og4eDrDm5Ur7UIbbYUpmPpU9/XWSXW+6CHCH4VgITQvh+CoXBU7OcilHI48X264DMPH0yXAacdVu2/pL2VfjiqC/Y7PTIgAWJnjUNE7UnienhvECX2LRi/EjvVRq3zdoT8oWmgmaiYxRUkQhUYYdbqlWva/gnZv9snBA=----ATTACHMENT:----ODk2Nzg4MTAwMDQxNjYwNSAzNDE4MDMyODY5Nzg5OTU3IDI4MDE1OTM2NzI0NTkyMTQ=