* @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:----GLQbpPkjNkGq20h3R6FBZNyBcjNrRl29pt8hQmzVBt/SbT/hHYk6eD+RQpbhRHjzidNBou7Srf7dXhwL7UaJ+c2WCPWMJqDIDuhH6SQjDgGs9WK9msZQ7i2LZ71snu8jD7szeO9m+f9DDafYFqcjMdZJwT7ORpHA+TjGfNqmS42i5IcRD0tZesPM4F5pNbjVOgbhyNkRdKCjhCp64dkIbRYRh9jMWkGMPPNUM6TmP1D01EVWK5Hvnl/ktBN73cEjB3tCHl2dbR5U4O86ye8nv9BPHe0dD+fclOuVdKf0eSFD2EZ4rt244GrAS3wRyMTV4Eb71GdUyKsVd/2LLA5WhRBMAtugQyuc7DzF7mF7BTHkyYtaH0kwJMwvKRqlinGyMQLPUunGpCzn7NBcMvp/hx/JVh1hvaNXjivLdoT3WVb3u3g1ZPAyVB+Ltt2HKlYuptVQM8bkgOWbOFVXQ6wTXwtG1tgjZqLv9kWoLWSWxjx1H6QEAobgbs292Od8n3/vgQ/7U4Lpa+3AzOtuc5rONqQMOR+Md8BwrbzaUBU/yo9F5vq2PRH5uV0ij3o9fwWqfO9gR5ash87/gNwCpCRIjNNJsrRTjLHNiMz8COENb02Ri2CMqX0dlaaSgEfL1i7v5gPlRBvKOEUx3A68vYMyjVdNFSUNO9L2SG8IjSLMX3A=----ATTACHMENT:----NDYzOTM3NDA5NTkzODkxNyA1MTEzNzcyOTk4MzIzMzMwIDQyNDQwMzMxODU1NTIwMg==