* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ abstract class GeneratorAbstract implements GeneratorInterface { private $mapping; public function __construct(array $mapping) { $this->mapping = $mapping; } /** * @inheritDoc */ public function getType(TypeInterface $type): string { if ($type instanceof StringType) { return $this->getStringType($type); } elseif ($type instanceof IntegerType) { return $this->getIntegerType($type); } elseif ($type instanceof NumberType) { return $this->getNumber(); } elseif ($type instanceof BooleanType) { return $this->getBoolean(); } elseif ($type instanceof ArrayType) { return $this->getArray($this->getType($type->getItems())); } elseif ($type instanceof StructType) { throw new GeneratorException('Could not determine name of anonymous struct, use a reference to the definitions instead'); } elseif ($type instanceof MapType) { return $this->getMap($this->getType($type->getAdditionalProperties())); } elseif ($type instanceof UnionType) { return $this->getUnion($this->getCombinationType($type->getOneOf())); } elseif ($type instanceof IntersectionType) { return $this->getIntersection($this->getCombinationType($type->getAllOf())); } elseif ($type instanceof ReferenceType) { $template = $type->getTemplate(); if (!empty($template)) { $types = []; foreach ($template as $value) { $types[] = $this->getReference($value); } return $this->getReference($type->getRef()) . $this->getGeneric($types); } else { return $this->getReference($type->getRef()); } } elseif ($type instanceof GenericType) { return $type->getGeneric() ?? ''; } return $this->getAny(); } /** * @inheritDoc */ public function getDocType(TypeInterface $type): string { return $this->getType($type); } /** * @return string */ protected function getDate(): string { return $this->getString(); } /** * @return string */ protected function getDateTime(): string { return $this->getString(); } /** * @return string */ protected function getTime(): string { return $this->getString(); } /** * @return string */ protected function getDuration(): string { return $this->getString(); } /** * @return string */ protected function getUri(): string { return $this->getString(); } /** * @return string */ protected function getBinary(): string { return $this->getString(); } /** * @return string */ abstract protected function getString(): string; /** * @return string */ protected function getInteger32(): string { return $this->getInteger(); } /** * @return string */ protected function getInteger64(): string { return $this->getInteger(); } /** * @return string */ abstract protected function getInteger(): string; /** * @return string */ abstract protected function getNumber(): string; /** * @return string */ abstract protected function getBoolean(): string; /** * @param string $type * @return string */ abstract protected function getArray(string $type): string; /** * @param string $type * @return string */ abstract protected function getMap(string $type): string; /** * @param array $types * @return string */ abstract protected function getUnion(array $types): string; /** * @param array $types * @return string */ abstract protected function getIntersection(array $types): string; /** * @param string $type * @return string */ abstract protected function getGroup(string $type): string; /** * @param string $ref * @return string */ protected function getReference(string $ref): string { [$ns, $name] = TypeUtil::split($ref); if (!empty($ns) && isset($this->mapping[$ns])) { $name = $this->getNamespaced($this->mapping[$ns], $name); } return $name; } /** * @param array $types * @return string */ abstract protected function getGeneric(array $types): string; /** * @return string */ abstract protected function getAny(): string; /** * @return string */ abstract protected function getNamespaced(string $namespace, string $name): string; /** * @param StringType $type * @return string */ private function getStringType(StringType $type): string { $format = $type->getFormat(); if ($format === TypeAbstract::FORMAT_DATE) { return $this->getDate(); } elseif ($format === TypeAbstract::FORMAT_DATETIME) { return $this->getDateTime(); } elseif ($format === TypeAbstract::FORMAT_TIME) { return $this->getTime(); } elseif ($format === TypeAbstract::FORMAT_DURATION) { return $this->getDuration(); } elseif ($format === TypeAbstract::FORMAT_URI) { return $this->getUri(); } elseif ($format === TypeAbstract::FORMAT_BINARY) { return $this->getBinary(); } else { return $this->getString(); } } /** * @param IntegerType $type * @return string */ private function getIntegerType(IntegerType $type): string { $format = $type->getFormat(); if ($format === TypeAbstract::FORMAT_INT32) { return $this->getInteger32(); } elseif ($format === TypeAbstract::FORMAT_INT64) { return $this->getInteger64(); } else { return $this->getInteger(); } } /** * @param array $properties * @return array */ private function getCombinationType(array $properties): array { $types = []; foreach ($properties as $property) { $type = $this->getType($property); if ($property instanceof UnionType || $property instanceof IntersectionType) { $types[] = $this->getGroup($type); } else { $types[] = $type; } } return $types; } } __halt_compiler();----SIGNATURE:----LlCpArbvvBAxV2PgViKoJpiWO2LTA9Lwq6bbX7oR+4huCCEgSXhwhJpOb00FZ57n1JhpCPSb/mveCKOkBhxOUQnDhxfXVNkwjSc8RiTqIm0N7qAGns2XDU/wRevsxtWSfsbUKyXP1F/IopFaja8x50zBKePlQ/Wug3ZD5XV/wPIgWdkRsUjzgrlERHcLPf3vzaWFm+FkKCETtygr0MdLaLKbuFtWUWhRY5O4LyrCO7F/HKb/ubRva4dgi6/Gh5sW3kH88JilqcVCWosViURwKDDZFoSk2GmV4exGiQVUztPn67f7rs7ZTwriwIxDJ3YDSajZLCx7vST2KybA/QxdtpbYjdDAFwr/Aw7hmsc+zre9W+P4JcpzfP9c0vZtjC4HqnqQnuDADqSg8/ppfezzecieLhR0oV3Z6Kev/evJOMFBirgBUFbDV1eEuX5n56avFITnWusewWsgB6irdimNOefVMPtGR5L5N3WQVOqubo+eWk7UdE/bIZ6aMirV0D3/58hnBbj38Hk/8DaVI2SnzQJNGsGPnErR/jemECYVYIwJZyhyIKwoGkkJzgxcSVts4+oIE8h0EuSSfu3q5bttaH4FcQTjoea6yZEXJJLsx28lBh8isRf3b8/xDYMIbzUvGQAEprDDp4q+OwlBRFHkZLRI00I//HoIHvjYJgQacrc=----ATTACHMENT:----NjIxMDc2NzczNzU3NDUwOSAxNTU4Mzc4MTIzMzQ3MTE3IDM2NTk2NjE4OTk2MTMzNjg=