* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ abstract class SchemaAbstract implements SchemaInterface { /** @var SchemaManagerInterface */ private $schemaManager; /** @var TypeInterface */ private $type; /** @var DefinitionsInterface */ private $definitions; /** @var string */ private $rootName; public function __construct(SchemaManagerInterface $schemaManager) { $this->schemaManager = $schemaManager; $this->definitions = new Definitions(); $this->build(); $type = $this->rootName; if (!$this->definitions->hasType($type)) { throw new InvalidSchemaException('Root schema does not exist at ' . get_class($this) . ', have you added a type via the newType method?'); } $this->type = TypeFactory::getReference($type); } public function getType(): TypeInterface { return $this->type; } public function getDefinitions(): DefinitionsInterface { return $this->definitions; } /** * @param string $name * @param TypeInterface $type */ protected function add(string $name, TypeInterface $type): void { $this->definitions->addType($name, $type); } /** * @param string $name * @return bool */ protected function has(string $name): bool { return $this->definitions->hasType($name); } /** * Main method to add a new type to the definitions of this schema * * @param string $name * @return Builder */ protected function newStruct(string $name): Builder { $builder = new Builder(); $this->definitions->addType($name, $builder->getType()); $this->rootName = $name; return $builder; } /** * @param string $name * @return MapType */ protected function newMap(string $name): MapType { $map = TypeFactory::getMap(); $this->definitions->addType($name, $map); return $map; } /** * Loads a remote schema and returns a reference to the root type * * @param string $name * @return ReferenceType */ protected function get(string $name): ReferenceType { $schema = $this->schemaManager->getSchema($name); if (!$schema instanceof SchemaInterface) { throw new \InvalidArgumentException('Could not load schema ' . $name); } $this->definitions->merge($schema->getDefinitions()); $type = $schema->getType(); if (!$type instanceof ReferenceType) { throw new \InvalidArgumentException('Loaded schema ' . $name . ' contains not a reference'); } return clone $type; } /** * Loads all definitions from another schema into this schema, so you can * use all definitions from the schema * * @param string $name */ protected function load(string $name): void { $schema = $this->schemaManager->getSchema($name); if ($schema instanceof SchemaInterface) { $this->definitions->merge($schema->getDefinitions()); } else { throw new \InvalidArgumentException('Could not load schema ' . $name); } } /** * Clones an existing type under a new name so you that you can modify * specific properties * * @param string $existingName * @param string $newName * @return TypeInterface */ protected function modify(string $existingName, string $newName): TypeInterface { $type = clone $this->definitions->getType($this->get($existingName)->getRef()); $this->definitions->addType($newName, $type); $this->rootName = $newName; return $type; } /** * Defines the root schema of this schema. By defualt the is the last schema * you have added via the newType method * * @param string $name */ protected function setRoot(string $name): void { $this->rootName = $name; } /** * Builds the schema, through the add method you can add a new type to the * schema and through the get method you can load an existing type */ abstract protected function build(): void; } __halt_compiler();----SIGNATURE:----p+FkMLSi9mKbmrkm8M1Jhb6np983qF7knQ7oauosSev5vZ2NhRPVxcAux5HjXDvkmyT3boAAVBZFnztWzifY1w7MGiisjEKBb97RHP7+Mi+CO8BL0XGsViONCjgjjC5XUrZsyjuLgLIWL1CB8+YrUusQsoOpR458dlJAZ9mKJ4B+pDyuwTCk0HAd/EHU/pApin7VfCQ3Ql/EnZz8e1IGtfwcwyPVg8fPprqJE1oTodfpLJ1mfkjfrmX2Cpwf0hNKvE+sUDuxrWSemj4B9tfmA0zpTJQBeTNjCvxl7CSuW8pH3rK/zfj8Ca+ZbsQP80Tdz1HRo9R1P7PgmIfsq0Rw81vqk4Rmaw2kcg8XE6RPIjV+G4073wboS1x8OOLihUY0UiK+ItqVGJh5CBVZckUO3o5V5QT0rHqQHX0D+IjZUoj2ETVUUkNSw7NcwMIgHrSZQH/TvchamQ0bB9M+GWUNH6JuuporSJKwN0l4l38pZk3zHC6fC5TU0MQ5nBd1t4N5vMPajLcuC4XW1NjHbY1OlTDvbxKwPLn4iXrEbqPGzA0saaMhYkbKH3XAu1awTdadyA/suMh6s8MdbC1W+FA/MSE4CRjp2nyUoF0JunNwax6nx+frBDYIltUzTvns+j8M++tZzxXtAJUfCpKTMGTaHjKn67w1RSq/CxWYza4W/6k=----ATTACHMENT:----NTg5MzA3NzE4NjUwMzIyMCA2OTM3NjUxMTI5NTk3NjcxIDcwMzQwNjc5NzAyMjg2Mjc=