Skip to content

Commit dda41f1

Browse files
author
Bernhard Schmitt
committed
Merge branch 'master' into fixPackageNameResolution
2 parents a5488dc + a29b312 commit dda41f1

118 files changed

Lines changed: 2355 additions & 504 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Classes/Command/ComponentCommandController.php

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Enum\EnumGenerator;
1313
use PackageFactory\AtomicFusion\PresentationObjects\Domain\PackageKey;
1414
use PackageFactory\AtomicFusion\PresentationObjects\Domain\PackageResolver;
15+
use PackageFactory\AtomicFusion\PresentationObjects\Infrastructure\DefensiveConfirmationFileWriter;
1516

1617
/**
1718
* The command controller for kick-starting PresentationObject components
@@ -25,16 +26,10 @@ class ComponentCommandController extends CommandController
2526
protected $packageResolver;
2627

2728
/**
28-
* @Flow\Inject
29-
* @var ComponentGenerator
30-
*/
31-
protected $componentGenerator;
32-
33-
/**
34-
* @Flow\Inject
35-
* @var EnumGenerator
29+
* @Flow\InjectConfiguration(path="componentGeneration.colocate")
30+
* @var bool
3631
*/
37-
protected $valueGenerator;
32+
protected $colocate;
3833

3934
/**
4035
* Create a new PresentationObject component and factory
@@ -50,6 +45,7 @@ class ComponentCommandController extends CommandController
5045
* The following values are allowed for types:
5146
*
5247
* * string, int, float, bool
48+
* * slot
5349
* * Value class names created with <u>component:kickstartvalue</u> in the same
5450
* component namespace
5551
* * Component class names created with <u>component:kickstart</u> in the same
@@ -60,19 +56,24 @@ class ComponentCommandController extends CommandController
6056
*
6157
* @param string $name The name of the new component
6258
* @param bool $listable If set, an additional list type will be generated
59+
* @param bool $yes If set, no confirmation is going to be required for overwriting files
6360
* @return void
6461
* @throws \Neos\Utility\Exception\FilesException
6562
*/
66-
public function kickStartCommand(string $name, bool $listable = false): void
63+
public function kickStartCommand(string $name, bool $listable = false, bool $yes = false): void
6764
{
65+
$componentGenerator = new ComponentGenerator(
66+
new DefensiveConfirmationFileWriter($this->output, $yes)
67+
);
6868
$package = $this->packageResolver->resolvePackage();
69-
$component = ComponentName::fromInput($name, PackageKey::fromPackage($package));
70-
$componentPackage = $this->packageResolver->resolvePackage((string)$component->getPackageKey());
69+
$componentName = ComponentName::fromInput($name, PackageKey::fromPackage($package));
70+
$componentPackage = $this->packageResolver->resolvePackage((string)$componentName->getPackageKey());
7171

72-
$this->componentGenerator->generateComponent(
73-
$component,
72+
$componentGenerator->generateComponent(
73+
$componentName,
7474
$this->request->getExceedingArguments(),
7575
$componentPackage->getPackagePath(),
76+
$this->colocate,
7677
$listable
7778
);
7879
}
@@ -92,20 +93,26 @@ public function kickStartCommand(string $name, bool $listable = false): void
9293
* @param string $name The name of the new pseudo-enum
9394
* @param string $type The type of the new pseudo-enum (must be one of: "string", "int")
9495
* @param array|string[] $values A comma-separated colon list of names:values for the new pseudo-enum, e.g. a,b,c , a:1,b:2,c:3 or a:1.2,b:2.4,c:3.6
96+
* @param bool $yes If set, no confirmation is going to be required for overwriting files
9597
* @return void
9698
*/
97-
public function kickStartEnumCommand(string $componentName, string $name, string $type, array $values = []): void
99+
public function kickStartEnumCommand(string $componentName, string $name, string $type, array $values = [], bool $yes = false): void
98100
{
101+
$enumGenerator = new EnumGenerator(
102+
new \DateTimeImmutable(),
103+
new DefensiveConfirmationFileWriter($this->output, $yes)
104+
);
99105
$package = $this->packageResolver->resolvePackage();
100-
$component = ComponentName::fromInput($componentName, PackageKey::fromPackage($package));
101-
$componentPackage = $this->packageResolver->resolvePackage((string)$component->getPackageKey());
106+
$componentNameObject = ComponentName::fromInput($componentName, PackageKey::fromPackage($package));
107+
$componentPackage = $this->packageResolver->resolvePackage((string)$componentNameObject->getPackageKey());
102108

103-
$this->valueGenerator->generateEnum(
104-
$component,
109+
$enumGenerator->generateEnum(
110+
$componentNameObject,
105111
$name,
106112
$type,
107113
$values,
108-
$componentPackage->getPackagePath()
114+
$componentPackage->getPackagePath(),
115+
$this->colocate
109116
);
110117
}
111118
}

Classes/Domain/AbstractImmutableArrayObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* The abstract class for immutable array objects
10-
* @template K
10+
* @template K of int|string
1111
* @template V
1212
* @extends \ArrayObject<K,V>
1313
*/

Classes/Domain/Component/Component.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function isGeneric(): bool
5353
*/
5454
public function getInterfaceContent(): string
5555
{
56-
return '<?php
56+
return '<?php declare(strict_types=1);
5757
namespace ' . $this->name->getPhpNamespace() . ';
5858
5959
' . $this->name->renderClassComment() . '
@@ -72,7 +72,7 @@ interface ' . $this->name->getSimpleInterfaceName() . ' extends ComponentPresent
7272
*/
7373
public function getClassContent(): string
7474
{
75-
return '<?php
75+
return '<?php declare(strict_types=1);
7676
namespace ' . $this->name->getPhpNamespace() . ';
7777
7878
' . $this->name->renderClassComment() . '
@@ -99,7 +99,7 @@ final class ' . $this->name->getSimpleClassName() . ' extends AbstractComponentP
9999
*/
100100
public function getFactoryContent(): string
101101
{
102-
return '<?php
102+
return '<?php declare(strict_types=1);
103103
namespace ' . $this->name->getPhpNamespace() . ';
104104
105105
' . $this->name->renderClassComment() . '
@@ -117,7 +117,7 @@ final class ' . $this->name->getSimpleFactoryName() . ' extends AbstractComponen
117117
*/
118118
public function getComponentArrayContent(): string
119119
{
120-
return '<?php
120+
return '<?php declare(strict_types=1);
121121
namespace ' . $this->name->getPhpNamespace() . ';
122122
123123
' . $this->name->renderClassComment() . '

Classes/Domain/Component/ComponentGenerator.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
*/
77

88
use Neos\Flow\Annotations as Flow;
9-
use Neos\Utility\Files;
9+
use PackageFactory\AtomicFusion\PresentationObjects\Domain\FileWriterInterface;
1010
use Symfony\Component\Yaml\Parser as YamlParser;
1111
use Symfony\Component\Yaml\Dumper as YamlWriter;
1212

1313
/**
1414
* The component generator domain service
1515
*
16-
* @Flow\Scope("singleton")
16+
* @Flow\Proxy(false)
1717
*/
1818
final class ComponentGenerator
1919
{
20+
private FileWriterInterface $fileWriter;
21+
22+
public function __construct(FileWriterInterface $fileWriter)
23+
{
24+
$this->fileWriter = $fileWriter;
25+
}
26+
2027
/**
2128
* @param ComponentName $componentName
2229
* @param array|string[] $serializedProps
2330
* @param string $packagePath
31+
* @param bool $colocate
2432
* @param bool $listable
2533
* @return void
2634
* @throws \Neos\Utility\Exception\FilesException
@@ -29,25 +37,19 @@ public function generateComponent(
2937
ComponentName $componentName,
3038
array $serializedProps,
3139
string $packagePath,
40+
bool $colocate,
3241
bool $listable = false
3342
): void {
3443
$props = Props::fromInputArray($componentName, $serializedProps);
3544
$component = new Component($componentName, $props, $listable);
3645

37-
$classPath = $componentName->getPhpFilePath($packagePath);
38-
if (!file_exists($classPath)) {
39-
Files::createDirectoryRecursively($classPath);
40-
}
41-
$fusionPath = $componentName->getFusionFilePath($packagePath);
42-
if (!file_exists($fusionPath)) {
43-
Files::createDirectoryRecursively($fusionPath);
44-
}
45-
file_put_contents($componentName->getInterfacePath($packagePath), $component->getInterfaceContent());
46-
file_put_contents($componentName->getClassPath($packagePath), $component->getClassContent());
47-
file_put_contents($componentName->getFactoryPath($packagePath), $component->getFactoryContent());
48-
file_put_contents($componentName->getFusionComponentPath($packagePath), $component->getFusionContent());
46+
$this->fileWriter->writeFile($componentName->getInterfacePath($packagePath, $colocate), $component->getInterfaceContent());
47+
$this->fileWriter->writeFile($componentName->getClassPath($packagePath, $colocate), $component->getClassContent());
48+
$this->fileWriter->writeFile($componentName->getFactoryPath($packagePath, $colocate), $component->getFactoryContent());
49+
$this->fileWriter->writeFile($componentName->getFusionComponentPath($packagePath), $component->getFusionContent());
50+
4951
if ($listable) {
50-
file_put_contents($componentName->getComponentArrayPath($packagePath), $component->getComponentArrayContent());
52+
$this->fileWriter->writeFile($componentName->getComponentArrayPath($packagePath, $colocate), $component->getComponentArrayContent());
5153
}
5254
$this->registerFactory($packagePath, $componentName);
5355
}
@@ -62,7 +64,6 @@ private function registerFactory(string $packagePath, ComponentName $componentNa
6264
$configurationPath = $packagePath . 'Configuration/';
6365
$configurationFilePath = $configurationPath . 'Settings.PresentationHelpers.yaml';
6466
if (!file_exists($configurationFilePath)) {
65-
Files::createDirectoryRecursively($configurationPath);
6667
$configuration = ['Neos' => ['Fusion' => ['defaultContext' => [
6768
$componentName->getHelperName() => $componentName->getFullyQualifiedFactoryName()
6869
]]]];
@@ -73,6 +74,6 @@ private function registerFactory(string $packagePath, ComponentName $componentNa
7374
}
7475

7576
$writer = new YamlWriter(2);
76-
file_put_contents($configurationFilePath, $writer->dump($configuration, 100));
77+
$this->fileWriter->writeFile($configurationFilePath, $writer->dump($configuration, 100));
7778
}
7879
}

Classes/Domain/Component/ComponentName.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ final class ComponentName
2121

2222
private string $name;
2323

24-
public function __construct(PackageKey $packageKey, FusionNamespace $fusionNamespace, string $name)
25-
{
24+
public function __construct(
25+
PackageKey $packageKey,
26+
FusionNamespace $fusionNamespace,
27+
string $name
28+
) {
2629
$this->packageKey = $packageKey;
2730
$this->fusionNamespace = $fusionNamespace;
2831
$this->name = $name;
@@ -204,29 +207,31 @@ public function getHelperName(): string
204207
return $this->packageKey->getSimpleName() . '.' . $this->name;
205208
}
206209

207-
public function getPhpFilePath(string $packagePath): string
210+
public function getPhpFilePath(string $packagePath, bool $colocate): string
208211
{
209-
return $packagePath . '/Classes/Presentation/' . $this->fusionNamespace->toFilePath() . '/' . $this->name;
212+
return $colocate
213+
? $this->getFusionFilePath($packagePath)
214+
: $packagePath . '/Classes/Presentation/' . $this->fusionNamespace->toFilePath() . '/' . $this->name;
210215
}
211216

212-
public function getInterfacePath(string $packagePath): string
217+
public function getInterfacePath(string $packagePath, bool $colocate): string
213218
{
214-
return $this->getPhpFilePath($packagePath) . '/'. $this->name . 'Interface.php';
219+
return $this->getPhpFilePath($packagePath, $colocate) . '/'. $this->name . 'Interface.php';
215220
}
216221

217-
public function getClassPath(string $packagePath): string
222+
public function getClassPath(string $packagePath, bool $colocate): string
218223
{
219-
return $this->getPhpFilePath($packagePath) . '/'. $this->name . '.php';
224+
return $this->getPhpFilePath($packagePath, $colocate) . '/'. $this->name . '.php';
220225
}
221226

222-
public function getFactoryPath(string $packagePath): string
227+
public function getFactoryPath(string $packagePath, bool $colocate): string
223228
{
224-
return $this->getPhpFilePath($packagePath) . '/'. $this->name . 'Factory.php';
229+
return $this->getPhpFilePath($packagePath, $colocate) . '/'. $this->name . 'Factory.php';
225230
}
226231

227-
public function getComponentArrayPath(string $packagePath): string
232+
public function getComponentArrayPath(string $packagePath, bool $colocate): string
228233
{
229-
return $this->getPhpFilePath($packagePath) . '/'. PluralName::forName($this->name) . '.php';
234+
return $this->getPhpFilePath($packagePath, $colocate) . '/'. PluralName::forName($this->name) . '.php';
230235
}
231236

232237
public function getFusionFilePath(string $packagePath): string

Classes/Domain/Component/PropType/ComponentArrayPropType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function getStyleGuideValue(int $nestingLevel = 0): string
4848
$componentPropType = new ComponentPropType($this->componentName, false);
4949
$componentStyleGuideValue = $componentPropType->getStyleGuideValue($nestingLevel + 1);
5050
return '{
51-
' . self::innerLeftPad($nestingLevel) . $componentStyleGuideValue . ',
52-
' . self::innerLeftPad($nestingLevel) . $componentStyleGuideValue . '
51+
' . self::innerLeftPad($nestingLevel) . '0 ' . $componentStyleGuideValue . '
52+
' . self::innerLeftPad($nestingLevel) . '1 ' .$componentStyleGuideValue . '
5353
' . self::outerLeftPad($nestingLevel) . '}';
5454
}
5555

Classes/Domain/Component/PropType/PropTypeFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Neos\Flow\Annotations as Flow;
99
use GuzzleHttp\Psr7\Uri;
1010
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\ComponentName;
11+
use PackageFactory\AtomicFusion\PresentationObjects\Presentation\Slot\SlotInterface;
1112
use Psr\Http\Message\UriInterface;
1213
use Sitegeist\Kaleidoscope\EelHelpers\ImageSourceHelperInterface;
1314

@@ -39,6 +40,8 @@ public static function fromInputString(ComponentName $parentComponentName, strin
3940
return new UriPropType($nullable);
4041
case 'ImageSource':
4142
return new ImageSourcePropType($nullable);
43+
case 'slot':
44+
return new SlotPropType($nullable);
4245
default:
4346
if ($isComponentArray = IsComponentArray::isSatisfiedByInputString($input)) {
4447
$input = \mb_substr($input, 6, \mb_strlen($input) - 7);
@@ -80,6 +83,8 @@ public static function fromReflectionProperty(\ReflectionProperty $property): Pr
8083
return new UriPropType($nullable);
8184
case ImageSourceHelperInterface::class:
8285
return new ImageSourcePropType($nullable);
86+
case SlotInterface::class:
87+
return new SlotPropType($nullable);
8388
default:
8489
if (IsEnum::isSatisfiedByClassName($type)) {
8590
/** @phpstan-var class-string<mixed> $type */
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
namespace PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\PropType;
3+
4+
/*
5+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
6+
*/
7+
8+
use Neos\Flow\Annotations as Flow;
9+
10+
/**
11+
* @Flow\Proxy(false)
12+
*/
13+
final class SlotPropType implements PropTypeInterface
14+
{
15+
private bool $nullable;
16+
17+
public function __construct(
18+
bool $nullable
19+
) {
20+
$this->nullable = $nullable;
21+
}
22+
23+
public function isNullable(): bool
24+
{
25+
return $this->nullable;
26+
}
27+
28+
public function getSimpleName(): string
29+
{
30+
return 'slot';
31+
}
32+
33+
public function getUseStatement(): string
34+
{
35+
return 'use PackageFactory\AtomicFusion\PresentationObjects\Presentation\Slot\SlotInterface;' . PHP_EOL;
36+
}
37+
38+
public function getType(): string
39+
{
40+
return ($this->nullable ? '?' : '') . 'SlotInterface';
41+
}
42+
43+
public function getStyleGuideValue(int $nestingLevel = 0): string
44+
{
45+
return '= \'- Add Slot Content -\'';
46+
}
47+
48+
public function getDefinitionData(string $propName): string
49+
{
50+
return '
51+
<PackageFactory.AtomicFusion.PresentationObjects:Slot presentationObject={presentationObject.' . $propName . '} />
52+
';
53+
}
54+
}

0 commit comments

Comments
 (0)