-
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.
Showing
17 changed files
with
294 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
48 changes: 48 additions & 0 deletions
48
packages/fractor-typoscript/src/Factory/PrettyPrinterFormatFactory.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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\Factory; | ||
|
||
use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption; | ||
use a9f\FractorTypoScript\ValueObject\TypoScriptPrettyPrinterFormatConfiguration; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; | ||
|
||
final readonly class PrettyPrinterFormatFactory | ||
{ | ||
public function __construct( | ||
private ContainerBagInterface $parameterBag | ||
) { | ||
} | ||
|
||
public function create(): TypoScriptPrettyPrinterFormatConfiguration | ||
{ | ||
$size = $this->parameterBag->has(TypoScriptProcessorOption::INDENT_SIZE) | ||
? $this->parameterBag->get(TypoScriptProcessorOption::INDENT_SIZE) | ||
: 4; | ||
|
||
$style = $this->parameterBag->has(TypoScriptProcessorOption::INDENT_CHARACTER) | ||
? $this->parameterBag->get(TypoScriptProcessorOption::INDENT_CHARACTER) | ||
: 'auto'; | ||
|
||
$addClosingGlobal = $this->parameterBag->has(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL) | ||
? $this->parameterBag->get(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL) | ||
: true; | ||
|
||
$includeEmptyLineBreaks = $this->parameterBag->has(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS) | ||
? $this->parameterBag->get(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS) | ||
: true; | ||
|
||
$indentConditions = $this->parameterBag->has(TypoScriptProcessorOption::INDENT_CONDITIONS) | ||
? $this->parameterBag->get(TypoScriptProcessorOption::INDENT_CONDITIONS) | ||
: false; | ||
|
||
return TypoScriptPrettyPrinterFormatConfiguration::fromValues( | ||
$size, | ||
$style, | ||
$addClosingGlobal, | ||
$includeEmptyLineBreaks, | ||
$indentConditions | ||
); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace a9f\FractorTypoScript\ValueObject; | ||
|
||
final readonly class TypoScriptPrettyPrinterFormatConfiguration | ||
{ | ||
public function __construct( | ||
private int $size, | ||
private string $style, | ||
private bool $addClosingGlobal, | ||
private bool $includeEmptyLineBreaks, | ||
private bool $indentConditions | ||
) { | ||
} | ||
|
||
/** | ||
* @phpstan-param \Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration::INDENTATION_STYLE_* $style | ||
*/ | ||
public static function fromValues( | ||
int $size, | ||
string $style, | ||
bool $addClosingGlobal, | ||
bool $includeEmptyLineBreaks, | ||
bool $indentConditions | ||
): self { | ||
return new self($size, $style, $addClosingGlobal, $includeEmptyLineBreaks, $indentConditions); | ||
} | ||
|
||
public function getSize(): int | ||
{ | ||
return $this->size; | ||
} | ||
|
||
public function getStyle(): string | ||
{ | ||
return $this->style; | ||
} | ||
|
||
public function shouldAddClosingGlobal(): bool | ||
{ | ||
return $this->addClosingGlobal; | ||
} | ||
|
||
public function shouldIncludeEmptyLineBreaks(): bool | ||
{ | ||
return $this->includeEmptyLineBreaks; | ||
} | ||
|
||
public function shouldIndentConditions(): bool | ||
{ | ||
return $this->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'; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
<?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::INDENT_CHARACTER => 'auto', | ||
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.
Oops, something went wrong.