* @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:----SlEK3cXgyUDKaGieGxRqI5hYD+jQx2OcJdxsL8/ABSym3G10yeEGlg8jAeWhm/opCuN+a8jC76/WKrun0PK+PK6be3m5m095/LmNtrzgFPsNogLQAkVPqjCHA8pVWDh7c4M49mUEIwuHaxtEIw91tcums6cBzQBueGfMyzruQUPMKePhnAXfHt4OFt8gVPyJ8FyvIFmKua5hiiULD7RgqtO3eQ8H2g+ig57ecbzp3cEymgBKaauQOm82CTYBdAyM7FRZLx5JbUDf2Kr99xn4QLNWxSQbDsLNubd+HTvjuDTPPa+n84UBBZWdLybd8Tw9Cpr1dLs9x0s3AmUnQUEuxSSoqXJi+kp05Mwzy5ykyoFUuE1BtwL1o+hBLcrUjJzMlZgsFKJKjX9GdH+R8UazL/M0TCJNvgN7P0dJlkCW6QmJBOvTHvdd0ow8gw3VWAC8kOvYRqRwDaNcRQe4SpgzFAX9KdYYBTsaHW5Ieq4ukJeseDpcPFDc0s6XOmHJdRFQHu/vwaX9Gd3eSzCRGOygi+ereNYjvOt3Hiu6UyUEsYHN2QQQGfYjuFQH/+K2tmDTdKcP/Csk16ZBiKbmuWIkfesduX/Mtzo3RPOMXJNK6muNiu/QdWrMKJghq0SikDv97DEOx/GUxggkvwD7A41ss/Jnl9hLPdcsY/Ls8Hb5CLU=----ATTACHMENT:----OTgyOTM4NDU0NjQ1NjAyMCA5Mjg2NzM1MDIwODc4NzczIDE2MzI1NDczNzIyNTc1NDU=