From eb860a59d68d40cd395a202b2497567e56541321 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 24 Aug 2021 01:34:34 +0200 Subject: [PATCH] Cherry-pick commits from researchgate upstream (#15) * 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 * Fixed schema validation for defaults Co-authored-by: Siad Ardroumli --- lib/avro/datum.php | 2 +- lib/avro/schema.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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 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;