-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStandardCompilationContext.php
66 lines (55 loc) · 1.84 KB
/
StandardCompilationContext.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Kiboko\Component\FastMap\Compiler;
use Kiboko\Component\Metadata\ClassReferenceMetadata;
use Kiboko\Contract\Mapping\Compiler\CompilationContextInterface;
use Kiboko\Contract\Metadata\ClassMetadataInterface;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
final readonly class StandardCompilationContext implements CompilationContextInterface
{
public function __construct(
private PropertyPathInterface $propertyPath,
private ?string $path = null,
private ?ClassMetadataInterface $class = null
) {}
public static function build(PropertyPathInterface $propertyPath, string $cachePath, string $fqcn): self
{
$fileName = null;
$className = null;
if (null !== $fqcn) {
if (false !== ($index = strrpos($fqcn, '\\'))) {
$namespace = substr($fqcn, 0, $index);
$className = substr($fqcn, $index + 1);
} else {
$namespace = null;
$className = $fqcn;
}
$fileName = $cachePath.'/'.$className.'.php';
}
return new self(
$propertyPath,
$fileName,
empty($className) ? null : new ClassReferenceMetadata($className, $namespace ?? null)
);
}
public function getPropertyPath(): PropertyPathInterface
{
return $this->propertyPath;
}
public function getFilePath(): ?string
{
return $this->path;
}
public function getClass(): ?ClassMetadataInterface
{
return $this->class;
}
public function getNamespace(): ?string
{
return null !== $this->class ? $this->class->getNamespace() : null;
}
public function getClassName(): ?string
{
return null !== $this->class ? $this->class->getName() : null;
}
}