Skip to content

Commit eb860a5

Browse files
tPl0chsiad007
andauthored
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 <siad.ardroumli@gmail.com>
1 parent 43e325e commit eb860a5

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/avro/datum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class AvroIODatumWriter
7676
* Schema used by this instance to write Avro data.
7777
* @var AvroSchema
7878
*/
79-
private $writers_schema;
79+
public $writers_schema;
8080

8181
/**
8282
* @param AvroSchema $writers_schema

lib/avro/schema.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,11 @@ public static function is_valid_datum($expected_schema, $datum)
459459
case self::REQUEST_SCHEMA:
460460
if (is_array($datum))
461461
{
462-
foreach ($expected_schema->fields() as $field)
463-
if (!array_key_exists($field->name(), $datum) || !self::is_valid_datum($field->type(), $datum[$field->name()]))
464-
return false;
462+
foreach ($expected_schema->fields() as $field) {
463+
$value = isset($datum[$field->name()]) ? $datum[$field->name()] : $field->default_value();
464+
if (!self::is_valid_datum($field->type(), $value))
465+
return false;
466+
}
465467
return true;
466468
}
467469
return false;

0 commit comments

Comments
 (0)