|
4 | 4 |
|
5 | 5 | namespace PackageFactory\NodeTypeObjects\Command; |
6 | 6 |
|
| 7 | +use Neos\ContentRepository\Core\NodeType\NodeType; |
7 | 8 | use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; |
8 | 9 | use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; |
9 | 10 | use Neos\Flow\Cli\CommandController; |
10 | 11 | use Neos\Flow\Package\FlowPackageInterface; |
11 | 12 | use Neos\Flow\Package\GenericPackage; |
12 | 13 | use Neos\Flow\Package\PackageManager; |
13 | 14 | use Neos\Utility\Files; |
| 15 | +use PackageFactory\NodeTypeObjects\Domain\NodeInterfaceNameSpecification; |
| 16 | +use PackageFactory\NodeTypeObjects\Domain\NodeInterfaceSpecification; |
14 | 17 | use PackageFactory\NodeTypeObjects\Domain\NodeObjectNameSpecification; |
15 | 18 | use PackageFactory\NodeTypeObjects\Domain\NodeObjectNameSpecificationCollection; |
16 | 19 | use PackageFactory\NodeTypeObjects\Domain\NodeObjectSpecification; |
@@ -39,14 +42,9 @@ public function injectContentRepositoryRegistry(ContentRepositoryRegistry $conte |
39 | 42 | */ |
40 | 43 | public function cleanCommand(string $packageKey): void |
41 | 44 | { |
42 | | - $package = $this->findFlowPackageByPackageKey($packageKey); |
| 45 | + $package = $this->getPackage($packageKey); |
43 | 46 |
|
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]); |
50 | 48 |
|
51 | 49 | $packagePath = $package->getPackagePath(); |
52 | 50 | if (!file_exists($packagePath . DIRECTORY_SEPARATOR . 'NodeTypes')) { |
@@ -80,55 +78,53 @@ public function cleanCommand(string $packageKey): void |
80 | 78 | */ |
81 | 79 | public function buildCommand(string $packageKey, string $crId = 'default'): void |
82 | 80 | { |
83 | | - $package = $this->findFlowPackageByPackageKey($packageKey); |
| 81 | + $package = $this->getPackage($packageKey); |
84 | 82 |
|
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]); |
91 | 84 |
|
92 | 85 | $contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString($crId)); |
93 | 86 | $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); |
103 | 87 |
|
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 |
110 | 90 |
|
111 | | - $specification = NodeObjectSpecification::createFromPackageAndNodeType($package, $nodeType, $nameSpecificationsCollection); |
| 91 | + $this->output->outputLine(); |
| 92 | + $this->output->outputLine('Creating NodeInterfaces'); |
| 93 | + $this->output->outputLine(); |
112 | 94 |
|
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 | + ); |
114 | 99 |
|
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 | + } |
130 | 109 |
|
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>'); |
132 | 128 | } |
133 | 129 | } |
134 | 130 |
|
@@ -179,16 +175,4 @@ protected function getPackage(string $packageKey): FlowPackageInterface & Generi |
179 | 175 | } |
180 | 176 | return $package; |
181 | 177 | } |
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 | | - } |
194 | 178 | } |
0 commit comments