Skip to content

Commit 357d6cc

Browse files
committed
[FEATURE] Add fractor-fluid and fractor-yaml
1 parent 9634592 commit 357d6cc

File tree

15 files changed

+303
-9
lines changed

15 files changed

+303
-9
lines changed

e2e/composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"a9f/fractor": "@dev",
66
"a9f/fractor-doc-generator": "@dev",
77
"a9f/fractor-extension-installer": "@dev",
8+
"a9f/fractor-fluid": "@dev",
89
"a9f/fractor-xml": "@dev",
10+
"a9f/fractor-yaml": "@dev",
911
"a9f/typo3-fractor": "@dev"
1012
},
1113
"require-dev": {

fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use a9f\Fractor\Testing\Fixture\FixtureFileFinder;
1515
use a9f\Fractor\Testing\Fixture\FixtureSplitter;
1616
use Nette\Utils\FileSystem;
17-
use Nette\Utils\Strings;
1817
use PHPUnit\Framework\TestCase;
1918
use Psr\Container\ContainerInterface;
2019

@@ -154,12 +153,7 @@ private function createInputFilePath(string $fixtureFilePath): string
154153
{
155154
$inputFileDirectory = dirname($fixtureFilePath);
156155

157-
// remove ".inc" suffix
158-
if (str_ends_with($fixtureFilePath, '.inc')) {
159-
$trimmedFixtureFilePath = Strings::substring($fixtureFilePath, 0, -4);
160-
} else {
161-
$trimmedFixtureFilePath = $fixtureFilePath;
162-
}
156+
$trimmedFixtureFilePath = $fixtureFilePath;
163157

164158
$fixtureBasename = pathinfo($trimmedFixtureFilePath, PATHINFO_BASENAME);
165159
return $inputFileDirectory . '/' . $fixtureBasename;

typo3-fractor/composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"a9f/fractor": "@dev",
1616
"a9f/fractor-doc-generator": "@dev",
1717
"a9f/fractor-extension-installer": "@dev",
18-
"a9f/fractor-xml": "@dev"
18+
"a9f/fractor-fluid": "@dev",
19+
"a9f/fractor-xml": "@dev",
20+
"a9f/fractor-yaml": "@dev"
1921
},
2022
"require-dev": {
2123
"ergebnis/composer-normalize": "^2.42",

typo3-fractor/config/typo3-10.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3+
use a9f\Typo3Fractor\TYPO3v10\Yaml\EmailFinisherFractor;
34
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
45

56
return static function (ContainerConfigurator $containerConfigurator): void {
67
$services = $containerConfigurator->services();
78
$services->defaults()
89
->autoconfigure()
910
->autowire();
11+
12+
$services->set(EmailFinisherFractor::class);
1013
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\Typo3Fractor\TYPO3v10\Yaml;
6+
7+
use a9f\FractorYaml\Contract\YamlFractorRule;
8+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
9+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
10+
11+
final class EmailFinisherFractor implements YamlFractorRule
12+
{
13+
/**
14+
* @var string
15+
*/
16+
private const FINISHERS = 'finishers';
17+
18+
/**
19+
* @var string
20+
*/
21+
private const OPTIONS = 'options';
22+
23+
/**
24+
* @var string
25+
*/
26+
private const RECIPIENT_ADDRESS = 'recipientAddress';
27+
28+
/**
29+
* @var string
30+
*/
31+
private const RECIPIENTS = 'recipients';
32+
33+
/**
34+
* @var string
35+
*/
36+
private const VARIANTS = 'variants';
37+
38+
public function getRuleDefinition(): RuleDefinition
39+
{
40+
return new RuleDefinition('Convert single recipient values to array for EmailFinisher', [
41+
new CodeSample(
42+
<<<'CODE_SAMPLE'
43+
finishers:
44+
-
45+
options:
46+
recipientAddress: [email protected]
47+
recipientName: 'Bar'
48+
CODE_SAMPLE
49+
,
50+
<<<'CODE_SAMPLE'
51+
finishers:
52+
-
53+
options:
54+
recipients:
55+
56+
CODE_SAMPLE
57+
),
58+
]);
59+
}
60+
61+
public function refactor(array $yaml): array
62+
{
63+
if (array_key_exists(self::FINISHERS, $yaml)) {
64+
$this->refactorFinishers($yaml[self::FINISHERS], $yaml);
65+
}
66+
67+
if (array_key_exists(self::VARIANTS, $yaml)) {
68+
foreach ($yaml[self::VARIANTS] as $variantKey => $variant) {
69+
if (!array_key_exists(self::FINISHERS, $variant)) {
70+
continue;
71+
}
72+
73+
$this->refactorFinishers(
74+
$variant[self::FINISHERS],
75+
$yaml[self::VARIANTS][$variantKey]
76+
);
77+
}
78+
}
79+
80+
return $yaml;
81+
}
82+
83+
/**
84+
* @param mixed[] $finishers
85+
* @param mixed[] $yamlToModify
86+
*/
87+
private function refactorFinishers(array $finishers, array &$yamlToModify): void
88+
{
89+
foreach ($finishers as $finisherKey => $finisher) {
90+
if (!array_key_exists('identifier', $finisher)) {
91+
continue;
92+
}
93+
94+
if (!in_array($finisher['identifier'], ['EmailToSender', 'EmailToReceiver'], true)) {
95+
continue;
96+
}
97+
98+
if (!array_key_exists(self::OPTIONS, $finisher)) {
99+
continue;
100+
}
101+
102+
$recipients = [];
103+
foreach ((array) $finisher[self::OPTIONS] as $optionKey => $optionValue) {
104+
if (!in_array(
105+
$optionKey,
106+
[
107+
'replyToAddress',
108+
'carbonCopyAddress',
109+
'blindCarbonCopyAddress',
110+
self::RECIPIENT_ADDRESS,
111+
'recipientName',
112+
],
113+
true
114+
)) {
115+
continue;
116+
}
117+
118+
if ($optionKey === 'replyToAddress') {
119+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['replyToRecipients'][] = $optionValue;
120+
} elseif ($optionKey === 'carbonCopyAddress') {
121+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['carbonCopyRecipients'][] = $optionValue;
122+
} elseif ($optionKey === 'blindCarbonCopyAddress') {
123+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS]['blindCarbonCopyRecipients'][] = $optionValue;
124+
}
125+
126+
unset(
127+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS][$optionKey]
128+
);
129+
}
130+
131+
if (isset($finisher[self::OPTIONS][self::RECIPIENT_ADDRESS])) {
132+
$recipients[$finisher[self::OPTIONS][self::RECIPIENT_ADDRESS]] = $finisher[self::OPTIONS]['recipientName'] ?: '';
133+
}
134+
135+
if (isset($finisher[self::OPTIONS][self::RECIPIENTS])) {
136+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS][self::RECIPIENTS] = array_merge(
137+
$recipients,
138+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS][self::RECIPIENTS]
139+
);
140+
} else {
141+
$yamlToModify[self::FINISHERS][$finisherKey][self::OPTIONS][self::RECIPIENTS] = $recipients;
142+
}
143+
}
144+
}
145+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rules\TYPO3v10\Yaml\EmailFinisherFractor;
6+
7+
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;
8+
use Iterator;
9+
use PHPUnit\Framework\Attributes\DataProvider;
10+
11+
final class EmailFinisherFractorTest extends AbstractFractorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures', '*.yaml');
22+
}
23+
24+
protected function additionalConfigurationFiles(): array
25+
{
26+
return [
27+
__DIR__ . '/config/config.php',
28+
];
29+
}
30+
31+
public function provideConfigFilePath(): ?string
32+
{
33+
return __DIR__ . '/config/fractor.php';
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
finishers:
2+
-
3+
options:
4+
recipients:
5+
6+
subject: 'Kontaktanfrage von Website'
7+
recipientAddress: [email protected]
8+
recipientName: Stadtwerke Bonn
9+
replyToAddress: [email protected]
10+
senderAddress: '{email}'
11+
senderName: '{lastName}'
12+
carbonCopyAddress: [email protected]
13+
blindCarbonCopyAddress: [email protected]
14+
format: html
15+
attachUploads: true
16+
identifier: EmailToReceiver
17+
-
18+
options:
19+
recipients:
20+
21+
subject: 'Kontaktanfrage von Website'
22+
recipientAddress: [email protected]
23+
recipientName: Stadtwerke Bonn
24+
replyToAddress: [email protected]
25+
senderAddress: '{email}'
26+
senderName: '{lastName}'
27+
carbonCopyAddress: [email protected]
28+
blindCarbonCopyAddress: [email protected]
29+
format: html
30+
attachUploads: true
31+
identifier: EmailToSender
32+
variants:
33+
-
34+
identifier: variant-1
35+
condition: 'formValues["foo"] == "bar"'
36+
finishers:
37+
-
38+
identifier: EmailToReceiver
39+
options:
40+
subject: 'Example Subject'
41+
recipientAddress: [email protected]
42+
recipientName: 'Example Recipient'
43+
senderAddress: [email protected]
44+
senderName: '{text-2} {text-1}'
45+
replyToAddress: '{email}'
46+
-----
47+
finishers:
48+
-
49+
options:
50+
recipients:
51+
[email protected]: 'Stadtwerke Bonn'
52+
53+
subject: 'Kontaktanfrage von Website'
54+
senderAddress: '{email}'
55+
senderName: '{lastName}'
56+
format: html
57+
attachUploads: true
58+
replyToRecipients:
59+
60+
carbonCopyRecipients:
61+
62+
blindCarbonCopyRecipients:
63+
64+
identifier: EmailToReceiver
65+
-
66+
options:
67+
recipients:
68+
[email protected]: 'Stadtwerke Bonn'
69+
70+
subject: 'Kontaktanfrage von Website'
71+
senderAddress: '{email}'
72+
senderName: '{lastName}'
73+
format: html
74+
attachUploads: true
75+
replyToRecipients:
76+
77+
carbonCopyRecipients:
78+
79+
blindCarbonCopyRecipients:
80+
81+
identifier: EmailToSender
82+
variants:
83+
-
84+
identifier: variant-1
85+
condition: 'formValues["foo"] == "bar"'
86+
finishers:
87+
-
88+
identifier: EmailToReceiver
89+
options:
90+
subject: 'Example Subject'
91+
senderAddress: [email protected]
92+
senderName: '{text-2} {text-1}'
93+
replyToRecipients:
94+
- '{email}'
95+
recipients:
96+
[email protected]: 'Example Recipient'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
finishers:
2+
-
3+
options:
4+
subject: 'Kontaktanfrage von Website'

typo3-fractor/tests/Rules/TYPO37/FlexForm/AddRenderTypeToFlexFormFractor/config/config.php typo3-fractor/tests/Rules/TYPO3v10/Yaml/EmailFinisherFractor/config/config.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
return static function (ContainerConfigurator $containerConfigurator): void {
66
$containerConfigurator->import(__DIR__ . '/../../../../../../config/application.php');
7-
$containerConfigurator->import(__DIR__ . '/../../../../../../../fractor-xml/config/application.php');
87
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use a9f\Fractor\Configuration\FractorConfiguration;
4+
use a9f\Typo3Fractor\Set\Typo3SetList;
5+
6+
return FractorConfiguration::configure()
7+
->withSets([Typo3SetList::TYPO3_10]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
4+
5+
return static function (ContainerConfigurator $containerConfigurator): void {
6+
$containerConfigurator->import(__DIR__ . '/../../../../../../config/application.php');
7+
};

0 commit comments

Comments
 (0)