function real_parse($avro) { $this->protocol = $avro["protocol"]; $this->namespace = $avro["namespace"]; $this->schemata = new AvroNamedSchemata(); $this->name = $avro["protocol"]; if (!is_null($avro["types"])) { $types = AvroSchema::real_parse($avro["types"], $this->namespace, $this->schemata); } if (!is_null($avro["messages"])) { foreach ($avro["messages"] as $messageName => $messageAvro) { $message = new AvroProtocolMessage($messageName, $messageAvro, $this); $this->messages[$messageName] = $message; } } }
public function __construct($name, $avro, $protocol) { $this->name = $name; if (array_key_exists('doc', $avro)) { $this->doc = $avro["doc"]; } $this->request = new AvroRecordSchema(new AvroName($name, null, $protocol->namespace), null, $avro['request'], $protocol->schemata, AvroSchema::REQUEST_SCHEMA); if (array_key_exists('response', $avro)) { if (!is_array($avro["response"])) { $this->response = $protocol->schemata->schema_by_name(new AvroName($avro['response'], $protocol->namespace, $protocol->namespace)); } else { $this->response = AvroSchema::real_parse($avro["response"], $protocol->namespace, $protocol->schemata); } } else { $avro['response'] = "null"; } if ($this->response == null) { $this->response = new AvroPrimitiveSchema($avro['response']); } if (isset($avro["one-way"])) { $this->is_one_way = $avro["one-way"]; } else { $errors = array(); $errors[] = self::SYSTEM_ERROR_TYPE; if (array_key_exists('errors', $avro)) { if (!is_array($avro["errors"])) { throw new AvroProtocolParseException("Errors must be an array"); } foreach ($avro["errors"] as $error_type) { $error_schema = $protocol->schemata->schema_by_name(new AvroName($error_type, $protocol->namespace, $protocol->namespace)); if (is_null($error_schema)) { throw new AvroProtocolParseException("Error type {$error_type} is unknown"); } $errors[] = $error_schema->qualified_name(); } } $this->errors = new AvroUnionSchema($errors, $protocol->namespace, $protocol->schemata); } if ($this->is_one_way && $this->response->type() != AvroSchema::NULL_TYPE) { throw new AvroProtocolParseException("One way message {$name} can't have a reponse"); } if ($this->is_one_way && !is_null($this->errors)) { throw new AvroProtocolParseException("One way message {$name} can't have errors"); } }