Skip to content

Commit

Permalink
Cherry-pick commits from researchgate upstream (#15)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tPl0ch and siad007 authored Aug 23, 2021
1 parent 43e325e commit eb860a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/avro/datum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/avro/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eb860a5

Please sign in to comment.