@@ -27,20 +27,51 @@ public function injectPackageManager(PackageManager $packageManager): void
2727 }
2828
2929 /**
30- * @param string $nodeTypeName Pattern for nodeTypeNames to generate classes for
30+ * Remove all NodeTypeObjects from the selected package
31+ *
3132 * @param string $packageKey PackageKey to store the classes in
3233 * @return void
3334 */
35+ public function cleanCommand (string $ packageKey ):void
36+ {
37+ if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
38+ $ package = $ this ->packageManager ->getPackage ($ packageKey );
39+ } else {
40+ $ this ->output ->outputLine ("Unknown package " . $ packageKey );
41+ $ this ->quit (1 );
42+ }
43+ if (!$ package instanceof FlowPackageInterface) {
44+ $ this ->output ->outputLine ($ packageKey . " is not a Flow package " );
45+ $ this ->quit (1 );
46+ }
47+
48+ $ packagePath = $ package ->getPackagePath ();
49+ $ files = Files::readDirectoryRecursively ($ packagePath , 'NodeObject.php ' );
50+ if (is_array ($ files )) {
51+ foreach ($ files as $ file ) {
52+ if (is_file ($ file )) {
53+ unlink ($ file );
54+ }
55+ $ this ->outputLine (' - ' . $ file );
56+ }
57+ }
58+ }
59+
60+ /**
61+ * Create new NodeTypeObjects for the selected Package
62+ *
63+ * @param string $packageKey PackageKey
64+ */
3465 public function buildCommand (string $ packageKey ):void
3566 {
3667 if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
3768 $ package = $ this ->packageManager ->getPackage ($ packageKey );
3869 } else {
39- $ this ->output ->outputLine ("Unknwn package " . $ packageKey );
70+ $ this ->output ->outputLine ("Unknown package " . $ packageKey );
4071 $ this ->quit (1 );
4172 }
4273 if (!$ package instanceof FlowPackageInterface) {
43- $ this ->output ->outputLine ($ packageKey . " is not a flow package " );
74+ $ this ->output ->outputLine ($ packageKey . " is not a Flow package " );
4475 $ this ->quit (1 );
4576 }
4677
@@ -75,6 +106,8 @@ public function buildCommand(string $packageKey):void
75106 $ filePath ,
76107 $ fileName ,
77108 );
109+
110+ $ this ->outputLine (' - ' . $ filePath . '/ ' . $ fileName );
78111 }
79112 }
80113
@@ -122,7 +155,7 @@ private function buildOne(FlowPackageInterface $package, NodeType $nodeType, str
122155 /**
123156 * @return $ annotationType;
124157 */
125- public function $ methodName (): ?$ phpType
158+ public function $ methodName(): ? $ phpType
126159 {
127160 return \$this->node->getProperty(' $ propertyName');
128161 }
@@ -133,6 +166,7 @@ public function $methodName (): ?$phpType
133166
134167 $ class = <<<EOL
135168 <?php
169+
136170 declare(strict_types=1);
137171
138172 namespace $ classNamespace;
@@ -141,24 +175,27 @@ public function $methodName (): ?$phpType
141175 use Neos\Flow\Annotations as Flow;
142176
143177 /**
144- * AUTOGENERATED DO NOT MODIFY
178+ * AUTOGENERATED CODE ... DO NOT MODIFY !!!
179+ *
145180 * run `./ nodetypeobjects:build` to regenerate this
146181 */
147182 #[Flow\Proxy(false)]
148- readonly class $ className {
183+ final readonly class $ className
184+ {
149185 private function __construct(
150186 public NodeInterface \$node
151- ) {}
187+ ) {
188+ }
152189
153190 public static function fromNode(NodeInterface \$node): self
154191 {
155192 if ( \$node->getNodeType()->getName() !== " $ nodeTypeName") {
156193 throw new \Exception("unsupported nodetype " . \$node->getNodeType()->getName());
157194 }
158195 return new self( \$node);
159- }
160- $ propertyAccesssors
196+ } $ propertyAccesssors
161197 }
198+
162199 EOL ;
163200
164201 Files::createDirectoryRecursively ($ filePath );
@@ -167,7 +204,5 @@ public static function fromNode(NodeInterface \$node): self
167204 $ filePath . '/ ' . $ fileName ,
168205 $ class
169206 );
170-
171- $ this ->outputLine ('Generated class %s (%s) from type %s ' , [$ classNamespace . '\\' . $ className , $ filePath . '/ ' . $ fileName , $ nodeType ->getName ()]);
172207 }
173208}
0 commit comments