From 19cad2d33dc21f9e2a14d4071d57dd994e97466c Mon Sep 17 00:00:00 2001 From: Siad Ardroumli Date: Mon, 4 May 2020 20:08:39 +0200 Subject: [PATCH 1/2] Fixed property visibility. As seen [here](https://github.com/researchgate/avro-php/blob/ff8841585ad76acbff5b673bafd5b70f35d311cb/lib/avro/data_file.php#L451) this property has to be public --- lib/avro/datum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/avro/datum.php b/lib/avro/datum.php index 1a17a06..f6dbd69 100644 --- a/lib/avro/datum.php +++ b/lib/avro/datum.php @@ -76,7 +76,7 @@ class AvroIODatumWriter * Schema used by this instance to write Avro data. * @var AvroSchema */ - private $writers_schema; + public $writers_schema; /** * @param AvroSchema $writers_schema From 4f0e7dc160375c37138cf3b6074a6e9da3f386eb Mon Sep 17 00:00:00 2001 From: Siad Ardroumli Date: Mon, 4 May 2020 20:13:13 +0200 Subject: [PATCH 2/2] Fixed schema validation for defaults --- lib/avro/schema.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/avro/schema.php b/lib/avro/schema.php index a8853d4..9401e11 100644 --- a/lib/avro/schema.php +++ b/lib/avro/schema.php @@ -459,9 +459,11 @@ public static function is_valid_datum($expected_schema, $datum) case self::REQUEST_SCHEMA: if (is_array($datum)) { - foreach ($expected_schema->fields() as $field) - if (!array_key_exists($field->name(), $datum) || !self::is_valid_datum($field->type(), $datum[$field->name()])) - return false; + foreach ($expected_schema->fields() as $field) { + $value = isset($datum[$field->name()]) ? $datum[$field->name()] : $field->default_value(); + if (!self::is_valid_datum($field->type(), $value)) + return false; + } return true; } return false;