44
55namespace PackageFactory \NodeTypeObjects \Command ;
66
7+ use Neos \ContentRepository \Core \NodeType \NodeType ;
78use Neos \ContentRepository \Core \SharedModel \ContentRepository \ContentRepositoryId ;
89use Neos \ContentRepositoryRegistry \ContentRepositoryRegistry ;
910use Neos \Flow \Cli \CommandController ;
1011use Neos \Flow \Package \FlowPackageInterface ;
1112use Neos \Flow \Package \GenericPackage ;
1213use Neos \Flow \Package \PackageManager ;
1314use Neos \Utility \Files ;
15+ use PackageFactory \NodeTypeObjects \Domain \NodeInterfaceNameSpecification ;
16+ use PackageFactory \NodeTypeObjects \Domain \NodeInterfaceSpecification ;
1417use PackageFactory \NodeTypeObjects \Domain \NodeObjectNameSpecification ;
1518use PackageFactory \NodeTypeObjects \Domain \NodeObjectNameSpecificationCollection ;
1619use PackageFactory \NodeTypeObjects \Domain \NodeObjectSpecification ;
@@ -39,14 +42,9 @@ public function injectContentRepositoryRegistry(ContentRepositoryRegistry $conte
3942 */
4043 public function cleanCommand (string $ packageKey ): void
4144 {
42- $ package = $ this ->findFlowPackageByPackageKey ($ packageKey );
45+ $ package = $ this ->getPackage ($ packageKey );
4346
44- if ($ package === null ) {
45- $ this ->output ->outputLine ('No packages found for packageKeys <error>"%s"</error>: ' , [$ packageKey ]);
46- $ this ->quit (1 );
47- } else {
48- $ this ->output ->outputLine ('Removing NodeObjects and NodeInterfaces from packages <info>"%s"</info>: ' , [$ package ->getPackageKey ()]);
49- }
47+ $ this ->output ->outputLine ('Removing NodeObjects and NodeInterfaces from package <info>"%s"</info>: ' , [$ packageKey ]);
5048
5149 $ packagePath = $ package ->getPackagePath ();
5250 if (!file_exists ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' )) {
@@ -80,55 +78,53 @@ public function cleanCommand(string $packageKey): void
8078 */
8179 public function buildCommand (string $ packageKey , string $ crId = 'default ' ): void
8280 {
83- $ package = $ this ->findFlowPackageByPackageKey ($ packageKey );
81+ $ package = $ this ->getPackage ($ packageKey );
8482
85- if ($ package === null ) {
86- $ this ->output ->outputLine ('No packages found for packageKeys <error>"%s"</error>: ' , [$ packageKey ]);
87- $ this ->quit (1 );
88- } else {
89- $ this ->output ->outputLine ('Building NodeObjects and NodeInterfaces for package <info>"%s"</info>: ' , [$ package ->getPackageKey ()]);
90- }
83+ $ this ->output ->outputLine ('Building NodeObjects and NodeInterfaces for package <info>"%s"</info>: ' , [$ packageKey ]);
9184
9285 $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ($ crId ));
9386 $ nodeTypeManager = $ contentRepository ->getNodeTypeManager ();
94- $ nodeTypes = $ nodeTypeManager ->getNodeTypes (true );
95- $ nameSpecifications = [];
96- foreach ($ nodeTypes as $ nodeType ) {
97- if (!str_starts_with ($ nodeType ->name ->value , $ package ->getPackageKey () . ': ' )) {
98- continue ;
99- }
100- $ nameSpecifications [$ nodeType ->name ->value ] = NodeObjectNameSpecification::createFromNodeType ($ nodeType );
101- }
102- $ nameSpecificationsCollection = new NodeObjectNameSpecificationCollection (...$ nameSpecifications );
10387
104- // loop 1 build interfaces
105- // loop 2 build objects
106- foreach ($ nodeTypes as $ nodeType ) {
107- if (!str_starts_with ($ nodeType ->name ->value , $ package ->getPackageKey () . ': ' )) {
108- continue ;
109- }
88+ // loop 1 build interfaces for all nodetypes in package, this is done first as in the next step
89+ // the node objects will create implements statements for all existing interfaces even those from other packages
11090
111- $ specification = NodeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType , $ nameSpecificationsCollection );
91+ $ this ->output ->outputLine ();
92+ $ this ->output ->outputLine ('Creating NodeInterfaces ' );
93+ $ this ->output ->outputLine ();
11294
113- Files::createDirectoryRecursively ($ specification ->directory );
95+ $ nodeTypes = array_filter (
96+ $ nodeTypeManager ->getNodeTypes (true ),
97+ fn (NodeType $ nodeType ) => str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )
98+ );
11499
115- $ generatedFiles = [];
116- if ($ specification ->classFilename ) {
117- file_put_contents (
118- $ specification ->classFilename ,
119- $ specification ->toPhpClassString ()
120- );
121- $ generatedFiles [] = $ specification ->names ->fullyQualifiedClassName ;
122- }
123- if ($ specification ->interfaceFilename ) {
124- file_put_contents (
125- $ specification ->interfaceFilename ,
126- $ specification ->toPhpInterfaceString ()
127- );
128- $ generatedFiles [] = $ specification ->names ->fullyQualifiedInterfaceName ;
129- }
100+ foreach ($ nodeTypes as $ nodeType ) {
101+ $ interfaceSpecification = NodeInterfaceSpecification::createFromPackageAndNodeType ($ package , $ nodeType );
102+ Files::createDirectoryRecursively ($ interfaceSpecification ->directory );
103+ file_put_contents (
104+ $ interfaceSpecification ->interfaceFilename ,
105+ $ interfaceSpecification ->toPhpString ()
106+ );
107+ $ this ->outputLine (' - ' . $ interfaceSpecification ->interfaceName ->nodeTypeName . ' -> <info> ' . $ interfaceSpecification ->interfaceFilename . '</info> ' );
108+ }
130109
131- $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> <info> ' . implode (', ' , $ generatedFiles ) . '</info> ' );
110+ // loop 2 build objects for all non abstract nodetypes in package
111+ $ this ->output ->outputLine ();
112+ $ this ->output ->outputLine ('Creating NodeObjects ' );
113+ $ this ->output ->outputLine ();
114+
115+ $ nonAbstractNodeTypes = array_filter (
116+ $ nodeTypeManager ->getNodeTypes (false ),
117+ fn (NodeType $ nodeType ) => str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )
118+ );
119+
120+ foreach ($ nonAbstractNodeTypes as $ nodeType ) {
121+ $ objectSpecification = NodeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType );
122+ Files::createDirectoryRecursively ($ objectSpecification ->directory );
123+ file_put_contents (
124+ $ objectSpecification ->classFilename ,
125+ $ objectSpecification ->toPhpString ()
126+ );
127+ $ this ->outputLine (' - ' . $ objectSpecification ->objectName ->nodeTypeName . ' -> <info> ' . $ objectSpecification ->objectName ->fullyQualifiedClassName . '</info> ' );
132128 }
133129 }
134130
@@ -153,7 +149,7 @@ protected function getPackage(string $packageKey): FlowPackageInterface & Generi
153149 $ this ->output ->outputLine ($ packageKey . " is not a Generic package " );
154150 $ this ->quit (1 );
155151 }
156-
152+ return $ package ;
157153 /**
158154 * @var array<int, array{namespace:string, classPath:string, mappingType:string}> $autoloadConfigurations
159155 */
@@ -179,16 +175,4 @@ protected function getPackage(string $packageKey): FlowPackageInterface & Generi
179175 }
180176 return $ package ;
181177 }
182-
183- protected function findFlowPackageByPackageKey (string $ packageKey ): ?FlowPackageInterface
184- {
185- if ($ this ->packageManager ->isPackageAvailable ($ packageKey ) === false ) {
186- return null ;
187- }
188- $ package = $ this ->packageManager ->getPackage ($ packageKey );
189- if ($ package instanceof FlowPackageInterface) {
190- return $ package ;
191- }
192- return null ;
193- }
194178}
0 commit comments