Skip to content

Commit 16641bc

Browse files
committed
Add second-level meta stub
1 parent 9915e42 commit 16641bc

21 files changed

+537
-0
lines changed

src/Mapping/Info/ClassInfo.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\DiscriminatorInfo;
8+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertiesInfoList;
9+
10+
/**
11+
* @template T of object
12+
*/
13+
final class ClassInfo
14+
{
15+
public readonly PropertiesInfoList $properties;
16+
17+
public ?DiscriminatorInfo $discriminator = null;
18+
19+
/**
20+
* @var non-empty-string|null
21+
*/
22+
public ?string $typeErrorMessage = null;
23+
24+
public ?bool $isNormalizeAsArray = null;
25+
26+
public function __construct(
27+
/**
28+
* Gets full qualified class name.
29+
*
30+
* @var class-string<T>
31+
*/
32+
public readonly string $name,
33+
) {
34+
$this->properties = new PropertiesInfoList();
35+
}
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\DiscriminatorInfo\DiscriminatorMapInfo;
8+
9+
final class DiscriminatorInfo
10+
{
11+
public function __construct(
12+
/**
13+
* @var non-empty-string
14+
*/
15+
public readonly string $field,
16+
public readonly DiscriminatorMapInfo $map,
17+
/**
18+
* @var non-empty-string|null
19+
*/
20+
public ?string $default = null,
21+
) {}
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo\DiscriminatorInfo;
6+
7+
use TypeLang\Mapper\Mapping\Info\TypeInfo;
8+
9+
/**
10+
* @template-implements \IteratorAggregate<non-empty-string, TypeInfo>
11+
*/
12+
final class DiscriminatorMapInfo implements \IteratorAggregate, \Countable
13+
{
14+
/**
15+
* @var array<non-empty-string, TypeInfo>
16+
*/
17+
private array $map = [];
18+
19+
/**
20+
* @param non-empty-string $value
21+
*/
22+
public function add(string $value, TypeInfo $type): void
23+
{
24+
$this->map[$value] = $type;
25+
}
26+
27+
public function getIterator(): \Traversable
28+
{
29+
return new \ArrayIterator($this->map);
30+
}
31+
32+
/**
33+
* @return int<0, max>
34+
*/
35+
public function count(): int
36+
{
37+
return \count($this->map);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo;
6+
7+
/**
8+
* @template-implements \IteratorAggregate<array-key, PropertyInfo>
9+
*/
10+
final class PropertiesInfoList implements \IteratorAggregate, \Countable
11+
{
12+
private array $properties = [];
13+
14+
public function add(PropertyInfo $property): void
15+
{
16+
$this->properties[$property->name] = $property;
17+
}
18+
19+
/**
20+
* @param non-empty-string $name
21+
*/
22+
public function getOrCreate(string $name): PropertyInfo
23+
{
24+
return $this->properties[$name] ??= new PropertyInfo($name);
25+
}
26+
27+
public function getIterator(): \Traversable
28+
{
29+
return new \ArrayIterator($this->properties);
30+
}
31+
32+
/**
33+
* @return int<0, max>
34+
*/
35+
public function count(): int
36+
{
37+
return \count($this->properties);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo\DefaultValueInfo;
8+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo\SkipConditionsInfoList;
9+
use TypeLang\Mapper\Mapping\Info\TypeInfo;
10+
11+
final class PropertyInfo
12+
{
13+
public ?DefaultValueInfo $default = null;
14+
15+
public ?TypeInfo $read = null;
16+
17+
public ?TypeInfo $write = null;
18+
19+
public readonly SkipConditionsInfoList $skip;
20+
21+
/**
22+
* @var non-empty-string|null
23+
*/
24+
public ?string $typeErrorMessage = null;
25+
26+
/**
27+
* @var non-empty-string|null
28+
*/
29+
public ?string $undefinedErrorMessage = null;
30+
31+
public function __construct(
32+
/**
33+
* @var non-empty-string
34+
*/
35+
public readonly string $name,
36+
) {
37+
$this->skip = new SkipConditionsInfoList();
38+
}
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo;
6+
7+
final class DefaultValueInfo
8+
{
9+
public function __construct(
10+
public readonly mixed $value,
11+
) {}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo;
6+
7+
abstract class SkipConditionInfo {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo\SkipConditionInfo;
8+
9+
final class EmptySkipConditionInfo extends SkipConditionInfo {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo\SkipConditionInfo;
8+
9+
final class ExpressionSkipConditionInfo extends SkipConditionInfo
10+
{
11+
/**
12+
* @var non-empty-string
13+
*/
14+
public const DEFAULT_CONTEXT_VARIABLE_NAME = 'this';
15+
16+
public function __construct(
17+
/**
18+
* @var non-empty-string
19+
*/
20+
public readonly string $expression,
21+
/**
22+
* @var non-empty-string
23+
*/
24+
public readonly string $context = self::DEFAULT_CONTEXT_VARIABLE_NAME,
25+
) {}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Mapping\Info;
6+
7+
use TypeLang\Mapper\Mapping\Info\ClassInfo\PropertyInfo\SkipConditionInfo;
8+
9+
final class NullSkipConditionInfo extends SkipConditionInfo {}

0 commit comments

Comments
 (0)