1313use Neos \Flow \Package \PackageManager ;
1414use Neos \Utility \Files ;
1515use Neos \Utility \Unicode \Functions as UnicodeFunctions ;
16+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectNameSpecification ;
17+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectNameSpecificationCollection ;
18+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectSpecification ;
1619use PackageFactory \NodeTypeObjects \Factory \NodeTypeObjectFileFactory ;
17- use PackageFactory \NodeTypeObjects \Factory \NodeTypeSpecificationFactory ;
20+ use PackageFactory \NodeTypeObjects \Factory \NodeTypeObjectSpecificationFactory ;
1821
1922class NodetypeObjectsCommandController extends CommandController
2023{
2124 private NodeTypeManager $ nodeTypeManager ;
2225 private PackageManager $ packageManager ;
23- private NodeTypeSpecificationFactory $ nodeTypeSpecificationFactory ;
24- private NodeTypeObjectFileFactory $ nodeTypeObjectFileFactory ;
25-
26-
2726
2827 public function injectNodeTypeManager (NodeTypeManager $ nodeTypeManager ): void
2928 {
@@ -35,18 +34,8 @@ public function injectPackageManager(PackageManager $packageManager): void
3534 $ this ->packageManager = $ packageManager ;
3635 }
3736
38- public function injectNodeTypeSpecificationFactory (NodeTypeSpecificationFactory $ nodeTypeSpecificationFactory ): void
39- {
40- $ this ->nodeTypeSpecificationFactory = $ nodeTypeSpecificationFactory ;
41- }
42-
43- public function injectNodeTypeObjectFileFactory (NodeTypeObjectFileFactory $ nodeTypeObjectFileFactory ): void
44- {
45- $ this ->nodeTypeObjectFileFactory = $ nodeTypeObjectFileFactory ;
46- }
47-
4837 /**
49- * Remove all NodeTypeObjects from the selected package
38+ * Remove all *NodeObject.php and *NodeInterface.php from the NodeTypes folder of the specified package
5039 *
5140 * @param string $packageKey PackageKey to store the classes in
5241 * @return void
@@ -65,7 +54,16 @@ public function cleanCommand(string $packageKey): void
6554 }
6655
6756 $ packagePath = $ package ->getPackagePath ();
68- $ files = Files::readDirectoryRecursively ($ packagePath , 'NodeObject.php ' );
57+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeObject.php ' );
58+ if (is_array ($ files )) {
59+ foreach ($ files as $ file ) {
60+ if (is_file ($ file )) {
61+ unlink ($ file );
62+ }
63+ $ this ->outputLine (' - ' . $ file );
64+ }
65+ }
66+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeInterface.php ' );
6967 if (is_array ($ files )) {
7068 foreach ($ files as $ file ) {
7169 if (is_file ($ file )) {
@@ -82,6 +80,55 @@ public function cleanCommand(string $packageKey): void
8280 * @param string $packageKey PackageKey
8381 */
8482 public function buildCommand (string $ packageKey ): void
83+ {
84+ $ package = $ this ->getPackage ($ packageKey );
85+
86+ $ nodeTypes = $ this ->nodeTypeManager ->getNodeTypes (true );
87+ $ nameSpecifications = [];
88+
89+ foreach ($ nodeTypes as $ nodeType ) {
90+ if (!str_starts_with ($ nodeType ->getName (), $ packageKey . ': ' )) {
91+ continue ;
92+ }
93+ $ nameSpecifications [$ nodeType ->getName ()] = NodeTypeObjectNameSpecification::createFromPackageAndNodeType ($ package , $ nodeType );
94+ }
95+
96+ $ nameSpecificationsCollection = new NodeTypeObjectNameSpecificationCollection (...$ nameSpecifications );
97+
98+ foreach ($ nodeTypes as $ nodeType ) {
99+ if (!str_starts_with ($ nodeType ->getName (), $ packageKey . ': ' )) {
100+ continue ;
101+ }
102+
103+ $ specification = NodeTypeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType , $ nameSpecificationsCollection );
104+
105+ Files::createDirectoryRecursively ($ specification ->names ->directory );
106+
107+ if ($ specification ->names ->className ) {
108+ file_put_contents (
109+ $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->className . '.php ' ,
110+ $ specification ->toPhpClassString ()
111+ );
112+ $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->className );
113+ }
114+
115+ if ($ specification ->names ->interfaceName ) {
116+ file_put_contents (
117+ $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->interfaceName . '.php ' ,
118+ $ specification ->toPhpInterfaceString ()
119+ );
120+ $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->interfaceName );
121+ }
122+ }
123+ }
124+
125+ /**
126+ * @param string $packageKey
127+ * @return mixed|FlowPackageInterface|GenericPackage|\Neos\Flow\Package\PackageInterface
128+ * @throws \Neos\Flow\Cli\Exception\StopCommandException
129+ * @throws \Neos\Flow\Package\Exception\UnknownPackageException
130+ */
131+ protected function getPackage (string $ packageKey ): mixed
85132 {
86133 if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
87134 $ package = $ this ->packageManager ->getPackage ($ packageKey );
@@ -105,14 +152,14 @@ public function buildCommand(string $packageKey): void
105152 $ namespace = null ;
106153 foreach ($ autoloadConfigurations as $ autoloadConfiguration ) {
107154 if (
108- $ autoloadConfiguration ['mappingType ' ] === 'psr-4 '
109- && str_ends_with ($ autoloadConfiguration ['namespace ' ], '\\NodeTypes \\' )
155+ $ autoloadConfiguration [ 'mappingType ' ] === 'psr-4 '
156+ && str_ends_with ($ autoloadConfiguration [ 'namespace ' ], '\\NodeTypes \\' )
110157 && (
111- $ autoloadConfiguration ['classPath ' ] === $ package ->getPackagePath () . 'NodeTypes '
112- || $ autoloadConfiguration ['classPath ' ] === $ package ->getPackagePath () . 'NodeTypes/ '
158+ $ autoloadConfiguration [ 'classPath ' ] === $ package ->getPackagePath () . 'NodeTypes '
159+ || $ autoloadConfiguration [ 'classPath ' ] === $ package ->getPackagePath () . 'NodeTypes/ '
113160 )
114161 ) {
115- $ namespace = $ autoloadConfiguration ['namespace ' ];
162+ $ namespace = $ autoloadConfiguration [ 'namespace ' ];
116163 break ;
117164 }
118165 }
@@ -121,28 +168,6 @@ public function buildCommand(string $packageKey): void
121168 $ this ->outputLine ('<error>No PSR4-NodeTypes namespace for the NodeTypes folder is registered via composer</error> ' );
122169 $ this ->quit (1 );
123170 }
124-
125- $ nodeTypes = $ this ->nodeTypeManager ->getNodeTypes (false );
126- foreach ($ nodeTypes as $ nodeType ) {
127- if (!str_starts_with ($ nodeType ->getName (), $ packageKey . ': ' )) {
128- continue ;
129- }
130-
131- $ specification = $ this ->nodeTypeSpecificationFactory ->createFromPackageKeyAndNodeType (
132- $ package ,
133- $ nodeType
134- );
135-
136- $ nodeTypeObjectFile = $ this ->nodeTypeObjectFileFactory ->createNodeTypeObjectPhpCodeFromNode ($ specification );
137-
138- Files::createDirectoryRecursively ($ nodeTypeObjectFile ->pathName );
139-
140- file_put_contents (
141- $ nodeTypeObjectFile ->fileNameWithPath ,
142- $ nodeTypeObjectFile ->fileContent
143- );
144-
145- $ this ->outputLine (' - ' . $ specification ->nodeTypeName . ' -> ' . $ specification ->className );
146- }
171+ return $ package ;
147172 }
148173}
0 commit comments