Skip to content

Commit 9135187

Browse files
author
Kirill Nesmeyanov
committed
Split type repository facade and runtime
1 parent 32725fb commit 9135187

40 files changed

+319
-452
lines changed

src/Mapper.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
use TypeLang\Mapper\Runtime\Parser\TypeParser;
1818
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
1919
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntime;
20-
use TypeLang\Mapper\Runtime\Repository\InMemoryTypeRepository;
21-
use TypeLang\Mapper\Runtime\Repository\LoggableTypeRepository;
22-
use TypeLang\Mapper\Runtime\Repository\TraceableTypeRepository;
20+
use TypeLang\Mapper\Runtime\Repository\InMemoryTypeRepositoryRuntime;
21+
use TypeLang\Mapper\Runtime\Repository\LoggableTypeRepositoryRuntime;
22+
use TypeLang\Mapper\Runtime\Repository\TraceableTypeRepositoryRuntime;
2323
use TypeLang\Mapper\Runtime\Repository\TypeRepository;
2424
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
25+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntime;
2526
use TypeLang\Mapper\Type\TypeInterface;
2627

2728
final class Mapper implements NormalizerInterface, DenormalizerInterface
@@ -57,20 +58,20 @@ private function createTypeParser(PlatformInterface $platform): TypeParserInterf
5758

5859
private function createTypeRepository(PlatformInterface $platform): TypeRepositoryInterface
5960
{
60-
$repository = TypeRepository::createFromPlatform(
61-
platform: $platform,
62-
parser: $this->parser,
63-
);
61+
$runtime = TypeRepositoryRuntime::createFromPlatform($platform, $this->parser);
6462

6563
if (($tracer = $this->config->getTracer()) !== null) {
66-
$repository = new TraceableTypeRepository($tracer, $repository);
64+
$runtime = new TraceableTypeRepositoryRuntime($tracer, $runtime);
6765
}
6866

6967
if (($logger = $this->config->getLogger()) !== null) {
70-
$repository = new LoggableTypeRepository($logger, $repository);
68+
$runtime = new LoggableTypeRepositoryRuntime($logger, $runtime);
7169
}
7270

73-
return new InMemoryTypeRepository($repository);
71+
return new TypeRepository(
72+
parser: $this->parser,
73+
runtime: new InMemoryTypeRepositoryRuntime($runtime),
74+
);
7475
}
7576

7677
/**

src/Mapping/Driver/AttributeDriver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
1212
use TypeLang\Mapper\Mapping\Metadata\TypeMetadata;
1313
use TypeLang\Mapper\Mapping\SkipWhen;
14-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
15-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
14+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
15+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1616

1717
final class AttributeDriver extends LoadableDriver
1818
{
1919
#[\Override]
2020
protected function load(
2121
\ReflectionClass $reflection,
2222
ClassMetadata $class,
23-
TypeRepositoryInterface $types,
24-
TypeParserInterface $parser,
23+
TypeRepositoryRuntimeInterface $types,
24+
TypeParserRuntimeInterface $parser,
2525
): void {
2626
foreach ($reflection->getProperties() as $property) {
2727
$metadata = $class->getPropertyOrCreate($property->getName());
@@ -71,8 +71,8 @@ protected function load(
7171
private function createType(
7272
string $type,
7373
\ReflectionProperty $property,
74-
TypeRepositoryInterface $types,
75-
TypeParserInterface $parser,
74+
TypeRepositoryRuntimeInterface $types,
75+
TypeParserRuntimeInterface $parser,
7676
): TypeMetadata {
7777
$statement = $parser->getStatementByDefinition($type);
7878

src/Mapping/Driver/DocBlockDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
1313
use TypeLang\Mapper\Mapping\Metadata\PropertyMetadata;
1414
use TypeLang\Mapper\Mapping\Metadata\TypeMetadata;
15-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
16-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
15+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
16+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1717
use TypeLang\Parser\Node\Stmt\TypeStatement;
1818
use TypeLang\PHPDoc\Parser;
1919
use TypeLang\PHPDoc\Standard\ParamTagFactory;
@@ -119,8 +119,8 @@ private function findType(\ReflectionClass $class, PropertyMetadata $meta): ?Typ
119119
protected function load(
120120
\ReflectionClass $reflection,
121121
ClassMetadata $class,
122-
TypeRepositoryInterface $types,
123-
TypeParserInterface $parser,
122+
TypeRepositoryRuntimeInterface $types,
123+
TypeParserRuntimeInterface $parser,
124124
): void {
125125
foreach ($reflection->getProperties() as $property) {
126126
$metadata = $class->getPropertyOrCreate($property->getName());

src/Mapping/Driver/Driver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace TypeLang\Mapper\Mapping\Driver;
66

77
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
8-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
9-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
8+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
9+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1010

1111
abstract class Driver implements DriverInterface
1212
{
@@ -16,8 +16,8 @@ public function __construct(
1616

1717
public function getClassMetadata(
1818
\ReflectionClass $class,
19-
TypeRepositoryInterface $types,
20-
TypeParserInterface $parser,
19+
TypeRepositoryRuntimeInterface $types,
20+
TypeParserRuntimeInterface $parser,
2121
): ClassMetadata {
2222
return $this->delegate->getClassMetadata($class, $types, $parser);
2323
}

src/Mapping/Driver/DriverInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace TypeLang\Mapper\Mapping\Driver;
66

77
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
8-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
9-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
8+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
9+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1010

1111
interface DriverInterface
1212
{
@@ -19,7 +19,7 @@ interface DriverInterface
1919
*/
2020
public function getClassMetadata(
2121
\ReflectionClass $class,
22-
TypeRepositoryInterface $types,
23-
TypeParserInterface $parser,
22+
TypeRepositoryRuntimeInterface $types,
23+
TypeParserRuntimeInterface $parser,
2424
): ClassMetadata;
2525
}

src/Mapping/Driver/InMemoryCachedDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace TypeLang\Mapper\Mapping\Driver;
66

77
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
8-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
9-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
8+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
9+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1010

1111
final class InMemoryCachedDriver extends Driver
1212
{
@@ -17,8 +17,8 @@ final class InMemoryCachedDriver extends Driver
1717

1818
public function getClassMetadata(
1919
\ReflectionClass $class,
20-
TypeRepositoryInterface $types,
21-
TypeParserInterface $parser,
20+
TypeRepositoryRuntimeInterface $types,
21+
TypeParserRuntimeInterface $parser,
2222
): ClassMetadata {
2323
// @phpstan-ignore-next-line : class-string<T> key contains ClassMetadata<T> instance
2424
return $this->memory[$class->name]

src/Mapping/Driver/LoadableDriver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use TypeLang\Mapper\Exception\Definition\DefinitionException;
88
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
9-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
10-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
9+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
10+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1111

1212
/**
1313
* Implements each driver that can supplement or modify existing
@@ -36,8 +36,8 @@ public function __construct(
3636
*/
3737
public function getClassMetadata(
3838
\ReflectionClass $class,
39-
TypeRepositoryInterface $types,
40-
TypeParserInterface $parser,
39+
TypeRepositoryRuntimeInterface $types,
40+
TypeParserRuntimeInterface $parser,
4141
): ClassMetadata {
4242
if (isset(self::$metadata[$class->getName()])) {
4343
/** @var ClassMetadata<TArg> */
@@ -68,7 +68,7 @@ public function getClassMetadata(
6868
abstract protected function load(
6969
\ReflectionClass $reflection,
7070
ClassMetadata $class,
71-
TypeRepositoryInterface $types,
72-
TypeParserInterface $parser,
71+
TypeRepositoryRuntimeInterface $types,
72+
TypeParserRuntimeInterface $parser,
7373
): void;
7474
}

src/Mapping/Driver/NullDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
namespace TypeLang\Mapper\Mapping\Driver;
66

77
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
8-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
9-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
8+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
9+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1010

1111
final class NullDriver implements DriverInterface
1212
{
1313
public function getClassMetadata(
1414
\ReflectionClass $class,
15-
TypeRepositoryInterface $types,
16-
TypeParserInterface $parser,
15+
TypeRepositoryRuntimeInterface $types,
16+
TypeParserRuntimeInterface $parser,
1717
): ClassMetadata {
1818
return new ClassMetadata($class->getName());
1919
}

src/Mapping/Driver/Psr16CachedDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Psr\SimpleCache\CacheInterface;
88
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
9-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
10-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
9+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
10+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1111

1212
final class Psr16CachedDriver extends CachedDriver
1313
{
@@ -22,8 +22,8 @@ public function __construct(
2222

2323
public function getClassMetadata(
2424
\ReflectionClass $class,
25-
TypeRepositoryInterface $types,
26-
TypeParserInterface $parser,
25+
TypeRepositoryRuntimeInterface $types,
26+
TypeParserRuntimeInterface $parser,
2727
): ClassMetadata {
2828
$index = $this->getKey($class);
2929

src/Mapping/Driver/ReflectionDriver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use TypeLang\Mapper\Mapping\Metadata\ClassMetadata;
1010
use TypeLang\Mapper\Mapping\Metadata\PropertyMetadata;
1111
use TypeLang\Mapper\Mapping\Metadata\TypeMetadata;
12-
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
13-
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
12+
use TypeLang\Mapper\Runtime\Parser\TypeParserRuntimeInterface;
13+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryRuntimeInterface;
1414
use TypeLang\Parser\Node\FullQualifiedName;
1515
use TypeLang\Parser\Node\Identifier;
1616
use TypeLang\Parser\Node\Name;
@@ -26,8 +26,8 @@ final class ReflectionDriver extends LoadableDriver
2626
protected function load(
2727
\ReflectionClass $reflection,
2828
ClassMetadata $class,
29-
TypeRepositoryInterface $types,
30-
TypeParserInterface $parser,
29+
TypeRepositoryRuntimeInterface $types,
30+
TypeParserRuntimeInterface $parser,
3131
): void {
3232
foreach ($reflection->getProperties() as $property) {
3333
if (!self::isValidProperty($property)) {
@@ -78,7 +78,7 @@ private function fillDefaultValue(\ReflectionProperty $property, PropertyMetadat
7878
private function fillType(
7979
\ReflectionProperty $property,
8080
PropertyMetadata $meta,
81-
TypeRepositoryInterface $types,
81+
TypeRepositoryRuntimeInterface $types,
8282
): void {
8383
$statement = $this->getTypeStatement($property);
8484

0 commit comments

Comments
 (0)