Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for PHP 8 attributes and symfony 7 #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ jobs:
strategy:
matrix:
php:
-
version: '7.4'
xdebug: '3.1.5'
-
version: '8.0'
xdebug: '3.1.5'
-
version: '8.1'
xdebug: '3.1.5'
-
version: '8.2'
xdebug: '3.2.1'
-
version: '8.3'
xdebug: '3.3.1'
runs-on: ubuntu-20.04
steps:
-
Expand Down Expand Up @@ -81,26 +78,20 @@ jobs:
strategy:
matrix:
php:
-
version: '7.4'
composer: --prefer-lowest
-
version: '8.0'
composer: --prefer-lowest
-
version: '8.1'
composer: --prefer-lowest
-
version: '8.2'
composer: --prefer-lowest
-
version: '7.4'
composer: --prefer-stable
version: '8.3'
composer: --prefer-lowest
-
version: '8.0'
version: '8.1'
composer: --prefer-stable
-
version: '8.1'
version: '8.2'
composer: --prefer-stable
-
version: '8.2'
Expand Down Expand Up @@ -190,16 +181,16 @@ jobs:
name: Download docker image
uses: actions/download-artifact@v2
with:
name: php-avro-serde-7.4
name: php-avro-serde-8.1
-
name: Load docker image
run: |
docker load -i php-avro-serde-7.4.tgz
docker load -i php-avro-serde-8.1.tgz
-
name: Install vendors
run: |
docker run -i --rm --net=host --sig-proxy=true --pid=host \
-v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" php-avro-serde:7.4 \
-v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" php-avro-serde:8.1 \
composer update --no-interaction --no-scripts --no-ansi --prefer-stable
-
name: Run PHPUnit Integration
Expand All @@ -209,5 +200,5 @@ jobs:
chmod a+x bin/wait-for-all.sh bin/wait-for-it.sh
make platform
docker run -i --rm --net=host --sig-proxy=true --pid=host \
-v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" php-avro-serde:7.4 \
-v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" php-avro-serde:8.1 \
vendor/bin/phpunit --group integration
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Avro SerDe for PHP 7.3+ and 8.0
# Avro SerDe for PHP 8.1+

[![php-confluent-serde Actions Status](https://github.com/flix-tech/avro-serde-php/workflows/php-confluent-serde/badge.svg?branch=master)](https://github.com/flix-tech/avro-serde-php/actions)
[![Maintainability](https://api.codeclimate.com/v1/badges/7500470a6812cf5a1ad5/maintainability)](https://codeclimate.com/github/flix-tech/avro-serde-php/maintainability)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^8.1",
"beberlei/assert": "^2.9.9|~3.0",
"flix-tech/confluent-schema-registry-api": "^8.0",
"guzzlehttp/promises": "^1.4.0|^2.0.0",
Expand All @@ -35,7 +35,7 @@
"phpunit/phpunit": "^9.4.2",
"phpbench/phpbench": "1.0.0-alpha2",
"vlucas/phpdotenv": "~2.4",
"symfony/serializer": "^3.4|^4.3",
"symfony/serializer": "^6.4|^7.0",
"doctrine/annotations": "^1.11"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion integrations/Symfony/Serializer/AvroSerDeEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(RecordSerializer $recordSerializer)
*
* @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException
*/
public function decode($data, $format, array $context = [])
public function decode(string $data, string $format, array $context = []): mixed
{
$readersSchema = $context[self::CONTEXT_DECODE_READERS_SCHEMA] ?? null;
Assert::that($readersSchema)->nullOr()->isInstanceOf(\AvroSchema::class);
Expand Down
30 changes: 30 additions & 0 deletions src/Objects/Schema/Generation/AttributeReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation;

class AttributeReader implements SchemaAttributeReader
{
public function readClassAttributes(\ReflectionClass $class): SchemaAttributes
{
$attributes = $class->getAttributes();

return $this->getSchemaAttributes(...$attributes);
}

public function readPropertyAttributes(\ReflectionProperty $property): SchemaAttributes
{
$attributes = $property->getAttributes();

return $this->getSchemaAttributes(...$attributes);
}

private function getSchemaAttributes(\ReflectionAttribute ...$attributes): SchemaAttributes
{
$attributes = array_map(fn ($attr) => $attr->newInstance(), $attributes);
$attributes = array_filter($attributes, fn ($attr) => $attr instanceof SchemaAttribute);

return new SchemaAttributes(...$attributes);
}
}
39 changes: 39 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroAliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;
use FlixTech\AvroSerializer\Objects\Schema\Generation\VariadicAttribute;

#[\Attribute]
final class AvroAliases implements VariadicAttribute
{
/**
* @var array<string>
*/
public array $aliases;

public function __construct(
string ...$aliases,
) {
$this->aliases = $aliases;
}

public function name(): string
{
return AttributeName::ALIASES;
}

public function value(): array
{
return $this->aliases;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes();
}
}
33 changes: 33 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroDefault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttribute;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;

#[\Attribute]
final class AvroDefault implements SchemaAttribute
{
public function __construct(
public mixed $value,
) {
}

public function name(): string
{
return AttributeName::DEFAULT;
}

public function value(): mixed
{
return $this->value;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes();
}
}
33 changes: 33 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroDoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttribute;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;

#[\Attribute]
final class AvroDoc implements SchemaAttribute
{
public function __construct(
public string $value
) {
}

public function name(): string
{
return AttributeName::DOC;
}

public function value(): string
{
return $this->value;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes();
}
}
47 changes: 47 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;
use FlixTech\AvroSerializer\Objects\Schema\Generation\TypeOnlyAttribute;

#[\Attribute]
final class AvroItems implements TypeOnlyAttribute
{
/**
* @var AvroType[]
*/
private array $types;

public function __construct(Type|AvroType ...$types)
{
$this->types = array_map(function ($type) {
if ($type instanceof AvroType) {
return $type;
}

return new AvroType($type);
}, $types);
}

/**
* @return AvroType[]
*/
public function value(): array
{
return $this->types;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes(...$this->value());
}

public function name(): string
{
return AttributeName::ITEMS;
}
}
33 changes: 33 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttribute;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;

#[\Attribute]
class AvroName implements SchemaAttribute
{
public function __construct(
public string $value,
) {
}

public function name(): string
{
return AttributeName::NAME;
}

public function value(): string
{
return $this->value;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes();
}
}
33 changes: 33 additions & 0 deletions src/Objects/Schema/Generation/Attributes/AvroNamespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes;

use FlixTech\AvroSerializer\Objects\Schema\AttributeName;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttribute;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes;

#[\Attribute]
class AvroNamespace implements SchemaAttribute
{
public function __construct(
public string $value,
) {
}

public function name(): string
{
return AttributeName::NAMESPACE;
}

public function value(): string
{
return $this->value;
}

public function attributes(): SchemaAttributes
{
return new SchemaAttributes();
}
}
Loading
Loading