-
Notifications
You must be signed in to change notification settings - Fork 1
/
Field.php
42 lines (33 loc) · 855 Bytes
/
Field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\GraphQL\Builder;
use function array_slice;
use function array_values;
use function end;
class Field {
/**
* @var list<string>
*/
protected array $path;
final public function __construct(
string ...$path,
) {
$this->path = array_values($path);
}
public function getName(): string {
return (string) end($this->path);
}
/**
* @return array<int, string>
*/
public function getPath(): array {
return $this->path;
}
public function getChild(string $name): static {
return new static(...$this->path, ...[$name]);
}
public function getParent(): static {
$path = array_slice($this->path, 0, -1);
$parent = new static(...$path);
return $parent;
}
}