1111use Neos \Flow \Package \GenericPackage ;
1212use Neos \Flow \Package \PackageManager ;
1313use Neos \Utility \Files ;
14- use PackageFactory \NodeTypeObjects \Factory \NodeTypeObjectFileFactory ;
15- use PackageFactory \NodeTypeObjects \Factory \NodeTypeSpecificationFactory ;
14+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectNameSpecification ;
15+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectNameSpecificationCollection ;
16+ use PackageFactory \NodeTypeObjects \Domain \NodeTypeObjectSpecification ;
1617
1718class NodetypeObjectsCommandController extends CommandController
1819{
1920 private PackageManager $ packageManager ;
20- private NodeTypeSpecificationFactory $ nodeTypeSpecificationFactory ;
21- private NodeTypeObjectFileFactory $ nodeTypeObjectFileFactory ;
21+
2222 private ContentRepositoryRegistry $ contentRepositoryRegistry ;
2323
2424 public function injectPackageManager (PackageManager $ packageManager ): void
@@ -31,19 +31,8 @@ public function injectContentRepositoryRegistry(ContentRepositoryRegistry $conte
3131 $ this ->contentRepositoryRegistry = $ contentRepositoryRegistry ;
3232 }
3333
34-
35- public function injectNodeTypeSpecificationFactory (NodeTypeSpecificationFactory $ nodeTypeSpecificationFactory ): void
36- {
37- $ this ->nodeTypeSpecificationFactory = $ nodeTypeSpecificationFactory ;
38- }
39-
40- public function injectNodeTypeObjectFileFactory (NodeTypeObjectFileFactory $ nodeTypeObjectFileFactory ): void
41- {
42- $ this ->nodeTypeObjectFileFactory = $ nodeTypeObjectFileFactory ;
43- }
44-
4534 /**
46- * Remove all NodeTypeObjects from the selected package
35+ * Remove all *NodeObject.php and *NodeInterface.php from the NodeTypes folder of the specified package
4736 *
4837 * @param string $packageKey PackageKey to store the classes in
4938 * @return void
@@ -62,7 +51,16 @@ public function cleanCommand(string $packageKey): void
6251 }
6352
6453 $ packagePath = $ package ->getPackagePath ();
65- $ files = Files::readDirectoryRecursively ($ packagePath , 'NodeObject.php ' );
54+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeObject.php ' );
55+ if (is_array ($ files )) {
56+ foreach ($ files as $ file ) {
57+ if (is_file ($ file )) {
58+ unlink ($ file );
59+ }
60+ $ this ->outputLine (' - ' . $ file );
61+ }
62+ }
63+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeInterface.php ' );
6664 if (is_array ($ files )) {
6765 foreach ($ files as $ file ) {
6866 if (is_file ($ file )) {
@@ -79,6 +77,57 @@ public function cleanCommand(string $packageKey): void
7977 * @param string $packageKey PackageKey
8078 */
8179 public function buildCommand (string $ packageKey , string $ crId = 'default ' ): void
80+ {
81+ $ package = $ this ->getPackage ($ packageKey );
82+
83+ $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ($ crId ));
84+ $ nodeTypeManager = $ contentRepository ->getNodeTypeManager ();
85+ $ nodeTypes = $ nodeTypeManager ->getNodeTypes ();
86+ $ nameSpecifications = [];
87+
88+ foreach ($ nodeTypes as $ nodeType ) {
89+ if (!str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )) {
90+ continue ;
91+ }
92+ $ nameSpecifications [$ nodeType ->name ->value ] = NodeTypeObjectNameSpecification::createFromPackageAndNodeType ($ package , $ nodeType );
93+ }
94+
95+ $ nameSpecificationsCollection = new NodeTypeObjectNameSpecificationCollection (...$ nameSpecifications );
96+
97+ foreach ($ nodeTypes as $ nodeType ) {
98+ if (!str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )) {
99+ continue ;
100+ }
101+
102+ $ specification = NodeTypeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType , $ nameSpecificationsCollection );
103+
104+ Files::createDirectoryRecursively ($ specification ->names ->directory );
105+
106+ if ($ specification ->names ->className ) {
107+ file_put_contents (
108+ $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->className . '.php ' ,
109+ $ specification ->toPhpClassString ()
110+ );
111+ $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->className );
112+ }
113+
114+ if ($ specification ->names ->interfaceName ) {
115+ file_put_contents (
116+ $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->interfaceName . '.php ' ,
117+ $ specification ->toPhpInterfaceString ()
118+ );
119+ $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->interfaceName );
120+ }
121+ }
122+ }
123+
124+ /**
125+ * @param string $packageKey
126+ * @return FlowPackageInterface
127+ * @throws \Neos\Flow\Cli\Exception\StopCommandException
128+ * @throws \Neos\Flow\Package\Exception\UnknownPackageException
129+ */
130+ protected function getPackage (string $ packageKey ): FlowPackageInterface
82131 {
83132 if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
84133 $ package = $ this ->packageManager ->getPackage ($ packageKey );
@@ -102,14 +151,14 @@ public function buildCommand(string $packageKey, string $crId = 'default'): void
102151 $ namespace = null ;
103152 foreach ($ autoloadConfigurations as $ autoloadConfiguration ) {
104153 if (
105- $ autoloadConfiguration ['mappingType ' ] === 'psr-4 '
106- && str_ends_with ($ autoloadConfiguration ['namespace ' ], '\\NodeTypes \\' )
154+ $ autoloadConfiguration [ 'mappingType ' ] === 'psr-4 '
155+ && str_ends_with ($ autoloadConfiguration [ 'namespace ' ], '\\NodeTypes \\' )
107156 && (
108- $ autoloadConfiguration ['classPath ' ] === $ package ->getPackagePath () . 'NodeTypes '
109- || $ autoloadConfiguration ['classPath ' ] === $ package ->getPackagePath () . 'NodeTypes/ '
157+ $ autoloadConfiguration [ 'classPath ' ] === $ package ->getPackagePath () . 'NodeTypes '
158+ || $ autoloadConfiguration [ 'classPath ' ] === $ package ->getPackagePath () . 'NodeTypes/ '
110159 )
111160 ) {
112- $ namespace = $ autoloadConfiguration ['namespace ' ];
161+ $ namespace = $ autoloadConfiguration [ 'namespace ' ];
113162 break ;
114163 }
115164 }
@@ -119,29 +168,6 @@ public function buildCommand(string $packageKey, string $crId = 'default'): void
119168 $ this ->quit (1 );
120169 }
121170
122- $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ($ crId ));
123- $ nodeTypeManager = $ contentRepository ->getNodeTypeManager ();
124- $ nodeTypes = $ nodeTypeManager ->getNodeTypes (false );
125- foreach ($ nodeTypes as $ nodeType ) {
126- if (!str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )) {
127- continue ;
128- }
129-
130- $ specification = $ this ->nodeTypeSpecificationFactory ->createFromPackageKeyAndNodeType (
131- $ package ,
132- $ nodeType
133- );
134-
135- $ nodeTypeObjectFile = $ this ->nodeTypeObjectFileFactory ->createNodeTypeObjectPhpCodeFromNode ($ specification );
136-
137- Files::createDirectoryRecursively ($ nodeTypeObjectFile ->pathName );
138-
139- file_put_contents (
140- $ nodeTypeObjectFile ->fileNameWithPath ,
141- $ nodeTypeObjectFile ->fileContent
142- );
143-
144- $ this ->outputLine (' - ' . $ specification ->nodeTypeName . ' -> ' . $ specification ->className );
145- }
171+ return $ package ;
146172 }
147173}
0 commit comments