Skip to content

Commit 57c5888

Browse files
committed
Added CallableTypeBuilder
1 parent 0542cc5 commit 57c5888

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Type\Builder;
6+
7+
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
8+
use TypeLang\Mapper\Runtime\Repository\TypeRepositoryInterface;
9+
use TypeLang\Mapper\Type\TypeInterface;
10+
use TypeLang\Parser\Node\Stmt\TypeStatement;
11+
12+
/**
13+
* @template-extends NamedTypeBuilder<TypeInterface>
14+
*/
15+
class CallableTypeBuilder extends NamedTypeBuilder
16+
{
17+
/**
18+
* @param non-empty-array<non-empty-string>|non-empty-string $names
19+
* @param \Closure(): TypeInterface $factory
20+
*/
21+
public function __construct(
22+
array|string $names,
23+
protected readonly \Closure $factory,
24+
) {
25+
parent::__construct($names);
26+
}
27+
28+
public function build(TypeStatement $statement, TypeRepositoryInterface $types, TypeParserInterface $parser): TypeInterface
29+
{
30+
$this->expectNoShapeFields($statement);
31+
$this->expectNoTemplateArguments($statement);
32+
33+
return ($this->factory)();
34+
}
35+
}

0 commit comments

Comments
 (0)