File tree 20 files changed +632
-11
lines changed
src/Objects/Schema/Generation
Integrations/Symfony/Serializer
Objects/Schema/Generation
20 files changed +632
-11
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation ;
6
+
7
+ class AttributeReader implements SchemaAttributeReader
8
+ {
9
+ public function readClassAttributes (\ReflectionClass $ class ): SchemaAttributes
10
+ {
11
+ $ attributes = $ class ->getAttributes ();
12
+
13
+ return $ this ->getSchemaAttributes (...$ attributes );
14
+ }
15
+
16
+ public function readPropertyAttributes (\ReflectionProperty $ property ): SchemaAttributes
17
+ {
18
+ $ attributes = $ property ->getAttributes ();
19
+
20
+ return $ this ->getSchemaAttributes (...$ attributes );
21
+ }
22
+
23
+ /**
24
+ * @param \ReflectionAttribute<object> ...$attributes
25
+ */
26
+ private function getSchemaAttributes (\ReflectionAttribute ...$ attributes ): SchemaAttributes
27
+ {
28
+ $ attributes = array_map (fn ($ attr ) => $ attr ->newInstance (), $ attributes );
29
+ $ attributes = array_filter ($ attributes , fn ($ attr ) => $ attr instanceof SchemaAttribute);
30
+
31
+ return new SchemaAttributes (...$ attributes );
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \VariadicAttribute ;
10
+
11
+ #[\Attribute]
12
+ final class AvroAliases implements VariadicAttribute
13
+ {
14
+ /**
15
+ * @var array<string>
16
+ */
17
+ public array $ aliases ;
18
+
19
+ public function __construct (
20
+ string ...$ aliases ,
21
+ ) {
22
+ $ this ->aliases = $ aliases ;
23
+ }
24
+
25
+ public function name (): string
26
+ {
27
+ return AttributeName::ALIASES ;
28
+ }
29
+
30
+ public function value (): array
31
+ {
32
+ return $ this ->aliases ;
33
+ }
34
+
35
+ public function attributes (): SchemaAttributes
36
+ {
37
+ return new SchemaAttributes ();
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ final class AvroDefault implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ public mixed $ value ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::DEFAULT ;
22
+ }
23
+
24
+ public function value (): mixed
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ final class AvroDoc implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ public string $ value ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::DOC ;
22
+ }
23
+
24
+ public function value (): string
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \TypeOnlyAttribute ;
10
+
11
+ #[\Attribute]
12
+ final class AvroItems implements TypeOnlyAttribute
13
+ {
14
+ /**
15
+ * @var AvroType[]
16
+ */
17
+ private array $ types ;
18
+
19
+ public function __construct (Type |AvroType ...$ types )
20
+ {
21
+ $ this ->types = array_map (function ($ type ) {
22
+ if ($ type instanceof AvroType) {
23
+ return $ type ;
24
+ }
25
+
26
+ return new AvroType ($ type );
27
+ }, $ types );
28
+ }
29
+
30
+ /**
31
+ * @return AvroType[]
32
+ */
33
+ public function value (): array
34
+ {
35
+ return $ this ->types ;
36
+ }
37
+
38
+ public function attributes (): SchemaAttributes
39
+ {
40
+ return new SchemaAttributes (...$ this ->value ());
41
+ }
42
+
43
+ public function name (): string
44
+ {
45
+ return AttributeName::ITEMS ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ class AvroName implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ public string $ value ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::NAME ;
22
+ }
23
+
24
+ public function value (): string
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ class AvroNamespace implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ public string $ value ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::NAMESPACE ;
22
+ }
23
+
24
+ public function value (): string
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ final class AvroOrder implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ private Order $ order ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::ORDER ;
22
+ }
23
+
24
+ public function value (): string
25
+ {
26
+ return $ this ->order ->value ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttribute ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
10
+
11
+ #[\Attribute]
12
+ final class AvroSize implements SchemaAttribute
13
+ {
14
+ public function __construct (
15
+ public int $ size ,
16
+ ) {
17
+ }
18
+
19
+ public function name (): string
20
+ {
21
+ return AttributeName::SIZE ;
22
+ }
23
+
24
+ public function value (): int
25
+ {
26
+ return $ this ->size ;
27
+ }
28
+
29
+ public function attributes (): SchemaAttributes
30
+ {
31
+ return new SchemaAttributes ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace FlixTech \AvroSerializer \Objects \Schema \Generation \Attributes ;
6
+
7
+ use FlixTech \AvroSerializer \Objects \Schema \AttributeName ;
8
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \SchemaAttributes ;
9
+ use FlixTech \AvroSerializer \Objects \Schema \Generation \VariadicAttribute ;
10
+
11
+ #[\Attribute]
12
+ final class AvroSymbols implements VariadicAttribute
13
+ {
14
+ /**
15
+ * @var array<string>
16
+ */
17
+ private array $ symbols ;
18
+
19
+ public function __construct (callable $ symbols )
20
+ {
21
+ $ this ->symbols = $ symbols ();
22
+ }
23
+
24
+ public function name (): string
25
+ {
26
+ return AttributeName::SYMBOLS ;
27
+ }
28
+
29
+ /**
30
+ * @return array<string>
31
+ */
32
+ public function value (): array
33
+ {
34
+ return $ this ->symbols ;
35
+ }
36
+
37
+ public function attributes (): SchemaAttributes
38
+ {
39
+ return new SchemaAttributes ();
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments