-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from andreaswolf/issue-197
[FEATURE] Keep TypoScript format
- Loading branch information
Showing
16 changed files
with
235 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/fractor-typoscript/src/Configuration/TypoScriptProcessorOption.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\Configuration; | ||
|
||
final class TypoScriptProcessorOption | ||
{ | ||
public const INDENT_SIZE = 'typoscript-processor-indent-size'; | ||
|
||
public const INDENT_CHARACTER = 'typoscript-processor-indent-character'; | ||
|
||
public const ADD_CLOSING_GLOBAL = 'typoscript-processor-add-closing-global'; | ||
|
||
public const INCLUDE_EMPTY_LINE_BREAKS = 'typoscript-processor-include-empty-line-breaks'; | ||
|
||
public const INDENT_CONDITIONS = 'typoscript-processor-indent-conditions'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/fractor-typoscript/src/ValueObject/TypoScriptPrettyPrinterFormatConfiguration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\ValueObject; | ||
|
||
use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
final readonly class TypoScriptPrettyPrinterFormatConfiguration | ||
{ | ||
public function __construct( | ||
public int $size, | ||
public string $style, | ||
public bool $addClosingGlobal, | ||
public bool $includeEmptyLineBreaks, | ||
public bool $indentConditions | ||
) { | ||
} | ||
|
||
public static function createFromParameterBag(ParameterBagInterface $parameterBag): self | ||
{ | ||
$size = $parameterBag->has(TypoScriptProcessorOption::INDENT_SIZE) | ||
? $parameterBag->get(TypoScriptProcessorOption::INDENT_SIZE) | ||
: 4; | ||
$size = is_int($size) ? $size : 4; | ||
|
||
$style = $parameterBag->has(TypoScriptProcessorOption::INDENT_CHARACTER) | ||
? $parameterBag->get(TypoScriptProcessorOption::INDENT_CHARACTER) | ||
: 'auto'; | ||
$style = is_string($style) ? $style : 'auto'; | ||
|
||
$addClosingGlobal = $parameterBag->has(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL) | ||
? (bool) $parameterBag->get(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL) | ||
: true; | ||
|
||
$includeEmptyLineBreaks = $parameterBag->has(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS) | ||
? (bool) $parameterBag->get(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS) | ||
: true; | ||
|
||
$indentConditions = $parameterBag->has(TypoScriptProcessorOption::INDENT_CONDITIONS) | ||
&& (bool) $parameterBag->get(TypoScriptProcessorOption::INDENT_CONDITIONS); | ||
|
||
return new self($size, $style, $addClosingGlobal, $includeEmptyLineBreaks, $indentConditions); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/fractor-typoscript/tests/Fixtures/DummyTypoScriptFractorRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\Tests\Fixtures; | ||
|
||
use a9f\FractorTypoScript\AbstractTypoScriptFractor; | ||
use a9f\FractorTypoScript\TypoScriptStatementsIterator; | ||
use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment; | ||
use Helmich\TypoScriptParser\Parser\AST\Statement; | ||
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
final class DummyTypoScriptFractorRule extends AbstractTypoScriptFractor | ||
{ | ||
public function refactor(Statement $statement): null|Statement|int | ||
{ | ||
if (! $statement instanceof Assignment) { | ||
return null; | ||
} | ||
|
||
if ($statement->object->absoluteName !== 'config.spamProtectEmailAddresses' | ||
|| $statement->value->value !== 'ascii' | ||
) { | ||
return null; | ||
} | ||
|
||
return TypoScriptStatementsIterator::REMOVE_NODE; | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
throw new BadMethodCallException('Not implemented yet'); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/fractor-typoscript/tests/TypoScriptFileProcessor/Fixtures/fixture.typoscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
page = PAGE | ||
page.10 = TEXT | ||
page.10.value = german | ||
|
||
[siteLanguage('languageId') == 1] | ||
page.10.value = english | ||
[global] | ||
|
||
config.spamProtectEmailAddresses = ascii | ||
----- | ||
page = PAGE | ||
page.10 = TEXT | ||
page.10.value = german | ||
|
||
[siteLanguage('languageId') == 1] | ||
page.10.value = english | ||
[global] |
29 changes: 29 additions & 0 deletions
29
packages/fractor-typoscript/tests/TypoScriptFileProcessor/TypoScriptFileProcessorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\Tests\TypoScriptFileProcessor; | ||
|
||
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; | ||
use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
|
||
class TypoScriptFileProcessorTest extends AbstractFractorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
$this->assertThatRuleIsApplied($filePath, DummyTypoScriptFractorRule::class); | ||
} | ||
|
||
public static function provideData(): \Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures', '*.typoscript'); | ||
} | ||
|
||
public function provideConfigFilePath(): ?string | ||
{ | ||
return __DIR__ . '/config/fractor.php'; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/fractor-typoscript/tests/TypoScriptFileProcessor/config/fractor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use a9f\Fractor\Configuration\FractorConfiguration; | ||
use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption; | ||
use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule; | ||
use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration; | ||
|
||
return FractorConfiguration::configure() | ||
->withOptions([ | ||
TypoScriptProcessorOption::INDENT_SIZE => 4, | ||
TypoScriptProcessorOption::INDENT_CHARACTER => PrettyPrinterConfiguration::INDENTATION_STYLE_SPACES, | ||
TypoScriptProcessorOption::ADD_CLOSING_GLOBAL => false, | ||
TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS => true, | ||
TypoScriptProcessorOption::INDENT_CONDITIONS => true, | ||
]) | ||
->withRules([DummyTypoScriptFractorRule::class]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters