|
12 | 12 | readonly class NodeTypeObjectNameSpecification |
13 | 13 | { |
14 | 14 | public function __construct( |
15 | | - public string $directory, |
16 | 15 | public string $nodeTypeName, |
17 | 16 | public string $phpNamespace, |
18 | 17 | public ?string $className, |
19 | | - public string $interfaceName |
| 18 | + public ?string $fullyQualifiedClassName, |
| 19 | + public ?string $interfaceName, |
| 20 | + public ?string $fullyQualifiedInterfaceName, |
20 | 21 | ) { |
21 | 22 | } |
22 | 23 |
|
23 | | - public static function createFromPackageAndNodeType( |
24 | | - FlowPackageInterface $package, |
| 24 | + public static function createFromNodeType( |
25 | 25 | NodeType $nodeType |
26 | 26 | ): self { |
27 | 27 |
|
28 | | - if (!str_starts_with($nodeType->getName(), $package->getPackageKey() . ':')) { |
29 | | - throw new \Exception("Only nodetypes from the given package are allowed"); |
30 | | - } |
| 28 | + list($packageKey, $nodeName) = explode(':', $nodeType->getName(), 2); |
31 | 29 |
|
32 | | - $localNameParts = explode('.', str_replace($package->getPackageKey() . ':', '', $nodeType->getName())); |
| 30 | + $localNameParts = explode('.', $nodeName); |
33 | 31 | $localName = array_pop($localNameParts); |
34 | | - $localNamespace = implode('.', $localNameParts); |
35 | 32 |
|
36 | | - $namespace = str_replace('.', '\\', $package->getPackageKey()) |
37 | | - . '\\NodeTypes' |
38 | | - . ($localNamespace ? '\\' . str_replace('.', '\\', $localNamespace) : '') |
39 | | - . '\\' . $localName; |
| 33 | + $phpNamespace = str_replace(['.', ':'], ['\\', '\\NodeTypes\\'], $nodeType->getName()); |
40 | 34 |
|
41 | | - $directory = $package->getPackagePath() |
42 | | - . 'NodeTypes' . DIRECTORY_SEPARATOR |
43 | | - . ($localNamespace ? str_replace('.', DIRECTORY_SEPARATOR, $localNamespace) . DIRECTORY_SEPARATOR : '') |
44 | | - . $localName; |
45 | 35 |
|
46 | 36 | if ($nodeType->isAbstract()) { |
47 | 37 | $className = null; |
48 | 38 | } else { |
49 | 39 | $className = str_replace('.', '\\', $localName) . 'NodeObject'; |
50 | 40 | } |
| 41 | + |
| 42 | + /** @var string|null $interfaceName */ |
51 | 43 | $interfaceName = str_replace('.', '\\', $localName) . 'NodeInterface'; |
52 | 44 |
|
53 | 45 | return new self( |
54 | | - $directory, |
55 | 46 | $nodeType->getName(), |
56 | | - $namespace, |
| 47 | + $phpNamespace, |
57 | 48 | $className, |
| 49 | + $className ? $phpNamespace . '\\' . $className : null, |
58 | 50 | $interfaceName, |
| 51 | + $interfaceName ? $phpNamespace . '\\' . $interfaceName : null |
59 | 52 | ); |
60 | 53 | } |
61 | 54 | } |
0 commit comments