Skip to content

Commit

Permalink
Merge pull request #34 from symplify/tv-config-builder
Browse files Browse the repository at this point in the history
Add config builder command - Symfony 5.3 feature
  • Loading branch information
TomasVotruba committed Jan 15, 2024
2 parents a98acad + cd8d058 commit bcb8af5
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 29 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/bare_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Bare Run on various PHP versions

on:
push:
tags:
- '*.72'
branches:
- 'main'

jobs:
bare_run:
Expand All @@ -23,4 +23,11 @@ jobs:
php-version: ${{ matrix.php_version }}
coverage: none

- run: php bin/config-transformer list --ansi
- run: mkdir nested-dir


- run: composer require symplify/config-transformer --dev --ansi
working-directory: nested-dir

- run: vendor/bin/config-transformer list --ansi
working-directory: nested-dir
6 changes: 1 addition & 5 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ jobs:
name: 'Tests'
run: vendor/bin/phpunit

-
name: 'PHP Linter'
run: vendor/bin/parallel-lint src tests

-
name: 'Check Active Classes'
run: vendor/bin/class-leak check bin src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\NodeVisitor\PrePrintNodeVisitorInterface"
Expand All @@ -49,7 +45,7 @@ jobs:
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none

# composer install cache - https://github.com/ramsey/composer-install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downgraded_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
-
uses: "shivammathur/setup-php@v2"
with:
php-version: 8.1
php-version: 8.2
coverage: none

# invoke patches
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bin/config-transformer"
],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"nette/utils": "^3.2",
"sebastian/diff": "^5.0",
"symfony/config": "^6.4",
Expand All @@ -26,8 +26,8 @@
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5",
"rector/rector": "^0.18.12",
"symplify/easy-coding-standard": "^12.0",
"rector/rector": "^0.19",
"symplify/easy-coding-standard": "^12.1",
"symplify/phpstan-extensions": "^11.4",
"symplify/vendor-patches": "^11.3",
"tomasvotruba/class-leak": "^0.2.6"
Expand Down Expand Up @@ -64,7 +64,8 @@
"symfony/polyfill-intl-grapheme": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
"symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*"
},
"scripts": {
"check-cs": "vendor/bin/ecs check --ansi",
Expand Down
17 changes: 5 additions & 12 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/ecs.php',
__DIR__ . '/rector.php',
return ECSConfig::configure()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$ecsConfig->sets([
SetList::COMMON,
SetList::PSR_12,
]);
};
])
->withRootFiles()
->withPreparedSets(psr12: true, common: true, strict: true);
74 changes: 74 additions & 0 deletions src/Console/Command/GenerateConfigClassesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace Symplify\ConfigTransformer\Console\Command;

use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

final class GenerateConfigClassesCommand extends Command
{
/**
* @var string[]
*/
private const EXTENSION_CLASSES = [
'Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension',
'Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension',
'Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension',
'Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension',
'Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension',
];

private SymfonyStyle $symfonyStyle;

protected function configure(): void
{
$this->setName('generate-config-classes');
$this->setDescription('Generate Symfony config classes to /var/cache/Symfony directory, see https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->symfonyStyle = new SymfonyStyle($input, $output);

$configBuilderGenerator = new ConfigBuilderGenerator(getcwd() . '/var/cache');
$this->symfonyStyle->newLine();

foreach (self::EXTENSION_CLASSES as $extensionClass) {
// skip for non-existing classes
if (! class_exists($extensionClass)) {
continue;
}

$configuration = $this->createExtensionConfiguration($extensionClass);
if (! $configuration instanceof ConfigurationInterface) {
continue;
}

$configBuilderGenerator->build($configuration);
}

return self::SUCCESS;
}

/**
* @param class-string $extensionClass
*/
private function createExtensionConfiguration(string $extensionClass): ?ConfigurationInterface
{
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('kernel.debug', false);

/** @var Extension $extension */
$extension = new $extensionClass();

return $extension->getConfiguration([], $containerBuilder);
}
}
8 changes: 6 additions & 2 deletions src/Console/ConfigTransformerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
namespace Symplify\ConfigTransformer\Console;

use Symfony\Component\Console\Application;
use Symplify\ConfigTransformer\Console\Command\GenerateConfigClassesCommand;
use Symplify\ConfigTransformer\Console\Command\SwitchFormatCommand;

final class ConfigTransformerApplication extends Application
{
public function __construct(SwitchFormatCommand $switchFormatCommand)
{
public function __construct(
SwitchFormatCommand $switchFormatCommand,
GenerateConfigClassesCommand $generateConfigClassesCommand
) {
// must be run before adding commands
// otherwise the default command will be overridden to a "list" command
parent::__construct();

$this->add($switchFormatCommand);
$this->add($generateConfigClassesCommand);

// hide unnecesary command
$this->get('help')->setHidden();
Expand Down
4 changes: 2 additions & 2 deletions tests/Helper/FixtureSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static function splitFileInfoToInputAndExpected(SplFileInfo $smartFileInf

public static function splitFileInfoToLocalInputAndExpectedFileInfos(
SplFileInfo $fileInfo,
bool $autoloadTestFixture = false,
bool $preserveDirStructure = false
bool $autoloadTestFixture = false,
bool $preserveDirStructure = false
): InputFileInfoAndExpectedFileInfo {
$inputAndExpected = self::splitFileInfoToInputAndExpected($fileInfo);

Expand Down

0 comments on commit bcb8af5

Please sign in to comment.