1212readonly class NodeTypeObjectNameSpecification
1313{
1414 public function __construct (
15- public string $ directory ,
1615 public string $ nodeTypeName ,
1716 public string $ phpNamespace ,
1817 public ?string $ className ,
19- public string $ interfaceName
18+ public ?string $ fullyQualifiedClassName ,
19+ public ?string $ interfaceName ,
20+ public ?string $ fullyQualifiedInterfaceName ,
2021 ) {
2122 }
2223
23- public static function createFromPackageAndNodeType (
24- FlowPackageInterface $ package ,
24+ public static function createFromNodeType (
2525 NodeType $ nodeType
2626 ): self {
2727
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 );
3129
32- $ localNameParts = explode ('. ' , str_replace ( $ package -> getPackageKey () . ' : ' , '' , $ nodeType -> getName ()) );
30+ $ localNameParts = explode ('. ' , $ nodeName );
3331 $ localName = array_pop ($ localNameParts );
34- $ localNamespace = implode ('. ' , $ localNameParts );
3532
36- $ namespace = str_replace ('. ' , '\\' , $ package ->getPackageKey ())
37- . '\\NodeTypes '
38- . ($ localNamespace ? '\\' . str_replace ('. ' , '\\' , $ localNamespace ) : '' )
39- . '\\' . $ localName ;
33+ $ phpNamespace = str_replace (['. ' , ': ' ], ['\\' , '\\NodeTypes \\' ], $ nodeType ->getName ());
4034
41- $ directory = $ package ->getPackagePath ()
42- . 'NodeTypes ' . DIRECTORY_SEPARATOR
43- . ($ localNamespace ? str_replace ('. ' , DIRECTORY_SEPARATOR , $ localNamespace ) . DIRECTORY_SEPARATOR : '' )
44- . $ localName ;
4535
4636 if ($ nodeType ->isAbstract ()) {
4737 $ className = null ;
@@ -51,11 +41,12 @@ public static function createFromPackageAndNodeType(
5141 $ interfaceName = str_replace ('. ' , '\\' , $ localName ) . 'NodeInterface ' ;
5242
5343 return new self (
54- $ directory ,
5544 $ nodeType ->getName (),
56- $ namespace ,
45+ $ phpNamespace ,
5746 $ className ,
47+ $ className ? $ phpNamespace . '\\' . $ className : null ,
5848 $ interfaceName ,
49+ $ interfaceName ? $ phpNamespace . '\\' . $ interfaceName : null
5950 );
6051 }
6152}
0 commit comments