diff --git a/.github/workflows/test-lang-php.yml b/.github/workflows/test-lang-php.yml index 5d1a4994b2c..faa94545909 100644 --- a/.github/workflows/test-lang-php.yml +++ b/.github/workflows/test-lang-php.yml @@ -55,7 +55,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - tools: composer:2.8.12 + tools: composer:2.9.3 - name: Get Composer Cache Directory id: composer-cache @@ -99,7 +99,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - tools: composer:2.8.12 + tools: composer:2.9.3 - name: Cache Local Maven Repository uses: actions/cache@v5 diff --git a/lang/php/lib/Schema/AvroField.php b/lang/php/lib/Schema/AvroField.php index d7c67e1b0f6..7f1d0bc7557 100644 --- a/lang/php/lib/Schema/AvroField.php +++ b/lang/php/lib/Schema/AvroField.php @@ -82,6 +82,7 @@ class AvroField extends AvroSchema implements AvroAliasedSchema */ private ?string $order; private ?array $aliases; + private ?string $doc; /** * @throws AvroSchemaParseException @@ -94,7 +95,8 @@ public function __construct( bool $hasDefault, mixed $default, ?string $order = null, - mixed $aliases = null + mixed $aliases = null, + ?string $doc = null ) { if (!AvroName::isWellFormedName($name)) { throw new AvroSchemaParseException('Field requires a "name" attribute'); @@ -111,6 +113,8 @@ public function __construct( $this->order = $order; self::hasValidAliases($aliases); $this->aliases = $aliases; + + $this->doc = $doc; } public function toAvro(): string|array @@ -131,13 +135,17 @@ public function toAvro(): string|array $avro[self::ORDER_ATTR] = $this->order; } + if (!is_null($this->doc)) { + $avro[AvroSchema::DOC_ATTR] = $this->doc; + } + return $avro; } /** * @returns string the name of this field */ - public function name() + public function name(): ?string { return $this->name; } @@ -153,7 +161,7 @@ public function defaultValue() /** * @returns boolean true if the field has a default and false otherwise */ - public function hasDefaultValue() + public function hasDefaultValue(): bool { return $this->hasDefault; } @@ -163,7 +171,7 @@ public function getAliases(): ?array return $this->aliases; } - public function hasAliases() + public function hasAliases(): bool { return null !== $this->aliases; } diff --git a/lang/php/lib/Schema/AvroRecordSchema.php b/lang/php/lib/Schema/AvroRecordSchema.php index b234b50cab3..903136874e5 100644 --- a/lang/php/lib/Schema/AvroRecordSchema.php +++ b/lang/php/lib/Schema/AvroRecordSchema.php @@ -74,6 +74,7 @@ public static function parseFields( $type = $field[AvroSchema::TYPE_ATTR] ?? null; $order = $field[AvroField::ORDER_ATTR] ?? null; $aliases = $field[AvroSchema::ALIASES_ATTR] ?? null; + $doc = $field[AvroSchema::DOC_ATTR] ?? null; $default = null; $has_default = false; @@ -110,7 +111,8 @@ public static function parseFields( hasDefault: $has_default, default: $default, order: $order, - aliases: $aliases + aliases: $aliases, + doc: $doc ); $field_names[] = $name; if ($new_field->hasAliases() && array_intersect($alias_names, $new_field->getAliases())) { diff --git a/lang/php/test/SchemaTest.php b/lang/php/test/SchemaTest.php index 8a0cb293126..41228d4b306 100644 --- a/lang/php/test/SchemaTest.php +++ b/lang/php/test/SchemaTest.php @@ -28,15 +28,15 @@ class SchemaExample { - public $name; - public $normalized_schema_string; + public string $name; + public string $normalized_schema_string; public function __construct( - public $schema_string, - public $is_valid, - $normalized_schema_string = null, - $name = null, - public $comment = null + public string $schema_string, + public bool $is_valid, + ?string $normalized_schema_string = null, + ?string $name = null, + public ?string $comment = null ) { $this->name = $name ?: $this->schema_string; $this->normalized_schema_string = $normalized_schema_string ?: json_encode(json_decode((string) $this->schema_string, true)); @@ -45,8 +45,8 @@ public function __construct( class SchemaTest extends TestCase { - private static $examples = []; - private static $valid_examples = []; + private static array $examples = []; + private static array $valid_examples = []; public function test_json_decode(): void { @@ -232,6 +232,27 @@ public function test_validate_repeated_aliases(): void ); } + public function test_doc_attribute_on_primitive_fields(): void + { + $schemaJson = <<toAvro(), flags: JSON_PRETTY_PRINT)); + } + public function test_logical_types_in_record(): void { $avro = <<