-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logical types and attributes support
- Loading branch information
1 parent
9e437c9
commit 5c3dedc
Showing
20 changed files
with
632 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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); | ||
} | ||
|
||
/** | ||
* @param \ReflectionAttribute<object> ...$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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/Objects/Schema/Generation/Attributes/AvroNamespace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 AvroOrder implements SchemaAttribute | ||
{ | ||
public function __construct( | ||
private Order $order, | ||
) { | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return AttributeName::ORDER; | ||
} | ||
|
||
public function value(): string | ||
{ | ||
return $this->order->value; | ||
} | ||
|
||
public function attributes(): SchemaAttributes | ||
{ | ||
return new SchemaAttributes(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 AvroSize implements SchemaAttribute | ||
{ | ||
public function __construct( | ||
public int $size, | ||
) { | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return AttributeName::SIZE; | ||
} | ||
|
||
public function value(): int | ||
{ | ||
return $this->size; | ||
} | ||
|
||
public function attributes(): SchemaAttributes | ||
{ | ||
return new SchemaAttributes(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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 AvroSymbols implements VariadicAttribute | ||
{ | ||
/** | ||
* @var array<string> | ||
*/ | ||
private array $symbols; | ||
|
||
public function __construct(callable $symbols) | ||
{ | ||
$this->symbols = $symbols(); | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return AttributeName::SYMBOLS; | ||
} | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
public function value(): array | ||
{ | ||
return $this->symbols; | ||
} | ||
|
||
public function attributes(): SchemaAttributes | ||
{ | ||
return new SchemaAttributes(); | ||
} | ||
} |
Oops, something went wrong.