Skip to content

Commit

Permalink
Merge pull request #28 from symplify/tv-files-too
Browse files Browse the repository at this point in the history
Remove deprecated symplify packages, narrow down to YAML to PHP conversion as stable one
  • Loading branch information
TomasVotruba committed Dec 16, 2023
2 parents f82da42 + b4072f9 commit 2321183
Show file tree
Hide file tree
Showing 79 changed files with 678 additions and 1,207 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ jobs:
name: 'PHP Linter'
run: vendor/bin/parallel-lint src tests

-
name: 'Check Commented Code'
run: vendor/bin/easy-ci check-commented-code src tests --ansi

-
name: 'Check Active Classes'
run: vendor/bin/class-leak check src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\NodeVisitor\PrePrintNodeVisitorInterface"
run: vendor/bin/class-leak check bin src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\NodeVisitor\PrePrintNodeVisitorInterface"


name: ${{ matrix.actions.name }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ composer.lock
/vendor

.phpunit.cache

# kernel cache
/var
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Convert Symfony XML/YAML configs to PHP
# Convert Symfony YAML configs to PHP

[![Downloads total](https://img.shields.io/packagist/dt/symplify/config-transformer.svg?style=flat-square)](https://packagist.org/packages/symplify/config-transformer/stats)

Expand Down
14 changes: 11 additions & 3 deletions bin/config-transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare(strict_types=1);

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symplify\ConfigTransformer\Kernel\ConfigTransformerKernel;
use Symplify\SymplifyKernel\ValueObject\KernelBootAndApplicationRun;

$possibleAutoloadPaths = [
// dependency
Expand All @@ -26,6 +27,13 @@
require_once $scoperAutoloadFilepath;
}

$configTransformerKernel = new ConfigTransformerKernel();
$configTransformerKernel->boot();

$kernelBootAndApplicationRun = new KernelBootAndApplicationRun(ConfigTransformerKernel::class);
$kernelBootAndApplicationRun->run();
$container = $configTransformerKernel->getContainer();

$configTransformerApplication = $container->get(\Symplify\ConfigTransformer\Console\ConfigTransformerApplication::class);

$input = new ArgvInput();
$output = new ConsoleOutput();
$configTransformerApplication->run($input, $output);
42 changes: 18 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,29 @@
],
"require": {
"php": ">=8.1",
"ext-dom": "*",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.17.1",
"symfony/console": "^6.3",
"symfony/config": "^6.4",
"symfony/console": "^6.4",
"symfony/dependency-injection": "6.1.*",
"symfony/expression-language": "^6.2",
"symfony/yaml": "^6.2",
"symplify/package-builder": "^11.3",
"symplify/php-config-printer": "^11.1",
"symplify/symplify-kernel": "^11.1"
"symfony/expression-language": "^6.4",
"symfony/filesystem": "^6.4",
"symfony/finder": "^6.4",
"symfony/http-kernel": "^6.1",
"symfony/yaml": "^6.4",
"symplify/php-config-printer": "^11.3.6",
"webmozart/assert": "^1.11"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^10.0",
"rector/rector": "^0.15.10",
"symfony/framework-bundle": "^6.1",
"symplify/easy-ci": "^11.1",
"symplify/easy-coding-standard": "^11.1",
"symplify/easy-testing": "^11.1",
"symplify/monorepo-builder": "^11.2",
"symplify/phpstan-extensions": "^11.1",
"symplify/vendor-patches": "^11.2",
"tomasvotruba/class-leak": "0.1.1.72",
"tomasvotruba/type-coverage": "^0.2",
"tomasvotruba/unused-public": "^0.1"
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5",
"rector/rector": "^0.18.12",
"symplify/easy-coding-standard": "^12.0",
"symplify/phpstan-extensions": "^11.4",
"symplify/vendor-patches": "^11.3",
"tomasvotruba/class-leak": "^0.2.6"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -67,7 +62,6 @@
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"rector": "vendor/bin/rector process --dry-run --ansi",
"release": "vendor/bin/monorepo-builder release patch --ansi"
"rector": "vendor/bin/rector process --dry-run --ansi"
}
}
36 changes: 6 additions & 30 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@

declare(strict_types=1);

use PhpParser\BuilderFactory;
use PhpParser\NodeFinder;
use SebastianBergmann\Diff\Differ;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Yaml\Parser;
use Symplify\ConfigTransformer\Console\ConfigTransformerApplication;
use Symplify\PackageBuilder\Console\Formatter\ColorConsoleDiffFormatter;
use Symplify\PackageBuilder\Console\Output\ConsoleDiffer;
use Symplify\PackageBuilder\Diff\DifferFactory;
use Symplify\PackageBuilder\Reflection\ClassLikeExistenceChecker;
use Symplify\PackageBuilder\Yaml\ParametersMerger;
use Symplify\ConfigTransformer\Console\Style\SymfonyStyleFactory;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->defaults()
->public()
->autowire();
->autowire()
->autoconfigure();

$services->load('Symplify\ConfigTransformer\\', __DIR__ . '/../src')
->exclude([
Expand All @@ -31,22 +23,6 @@
__DIR__ . '/../src/ValueObject',
]);

// console
$services->alias(Application::class, ConfigTransformerApplication::class);

// color diff
$services->set(DifferFactory::class);
$services->set(Differ::class)
->factory([service(DifferFactory::class), 'create']);

$services->set(ConsoleDiffer::class);

$services->set(ColorConsoleDiffFormatter::class);

$services->set(BuilderFactory::class);
$services->set(NodeFinder::class);
$services->set(Parser::class);

$services->set(ClassLikeExistenceChecker::class);
$services->set(ParametersMerger::class);
$services->set(SymfonyStyle::class)
->factory([service(SymfonyStyleFactory::class), 'create']);
};
5 changes: 0 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ parameters:
- '*/tests/**/Source/*'
- '*/tests/**/Fixture/*'

unused_public:
methods: true
properties: true
constants: true

ignoreErrors:
-
message: '#Parameter \#1 \$commandName of method Symfony\\Component\\Console\\Application\:\:setDefaultCommand\(\) expects string, string\|null given#'
Expand Down
31 changes: 0 additions & 31 deletions src/Collector/XmlImportCollector.php

This file was deleted.

22 changes: 7 additions & 15 deletions src/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\ConfigTransformer;

use Nette\Utils\FileSystem;
use Nette\Utils\Strings;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\FileLocator;
Expand All @@ -14,23 +15,21 @@
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\Finder\SplFileInfo;
use Symplify\ConfigTransformer\DependencyInjection\ExtensionFaker;
use Symplify\ConfigTransformer\DependencyInjection\Loader\MissingAutodiscoveryDirectoryTolerantYamlFileLoader;
use Symplify\ConfigTransformer\DependencyInjection\Loader\SkippingPhpFileLoader;
use Symplify\ConfigTransformer\DependencyInjection\LoaderFactory\IdAwareXmlFileLoaderFactory;
use Symplify\ConfigTransformer\Enum\Format;
use Symplify\ConfigTransformer\Exception\NotImplementedYetException;
use Symplify\ConfigTransformer\ValueObject\ContainerBuilderAndFileContent;
use Symplify\SmartFileSystem\SmartFileInfo;
use Symplify\SmartFileSystem\SmartFileSystem;

final class ConfigLoader
{
/**
* @see https://regex101.com/r/4Uanps/4
* @var string
*/
private const PHP_CONST_REGEX = '#!php/const:?\s*([a-zA-Z0-9_\\\\]+(::[a-zA-Z0-9_]+)?)+(:\s*(.*))?#';
private const PHP_CONST_REGEX = '#!php/const:?\s*([a-zA-Z0-9_\\\]+(::\w+)?)+(:\s*(.*))?#';

/**
* @see https://regex101.com/r/spi4ir/1
Expand All @@ -39,18 +38,16 @@ final class ConfigLoader
private const UNQUOTED_PARAMETER_REGEX = '#^(\s*\w+:\s+)(\%(.*?)%)(.*?)?$#m';

public function __construct(
private readonly IdAwareXmlFileLoaderFactory $idAwareXmlFileLoaderFactory,
private readonly SmartFileSystem $smartFileSystem,
private readonly ExtensionFaker $extensionFaker
) {
}

public function createAndLoadContainerBuilderFromFileInfo(
SmartFileInfo $smartFileInfo,
SplFileInfo $smartFileInfo,
): ContainerBuilderAndFileContent {
$containerBuilder = new ContainerBuilder();

$delegatingLoader = $this->createLoaderBySuffix($containerBuilder, $smartFileInfo->getSuffix());
$delegatingLoader = $this->createLoaderBySuffix($containerBuilder, $smartFileInfo->getExtension());
$fileRealPath = $smartFileInfo->getRealPath();

// correct old syntax of tags so we can parse it
Expand All @@ -63,7 +60,7 @@ public function createAndLoadContainerBuilderFromFileInfo(
static fn (array $match): string => $match[1] . '"' . $match[2] . ($match[4] ?? '') . '"'
);

if (in_array($smartFileInfo->getSuffix(), [Format::YML, Format::YAML], true)) {
if (in_array($smartFileInfo->getExtension(), [Format::YML, Format::YAML], true)) {
$content = Strings::replace(
$content,
self::PHP_CONST_REGEX,
Expand All @@ -75,7 +72,7 @@ public function createAndLoadContainerBuilderFromFileInfo(
);
if ($content !== $smartFileInfo->getContents()) {
$fileRealPath = sys_get_temp_dir() . '/__symplify_config_tranformer_clean_yaml/' . $smartFileInfo->getFilename();
$this->smartFileSystem->dumpFile($fileRealPath, $content);
FileSystem::write($fileRealPath, $content);
}

$this->extensionFaker->fakeInContainerBuilder($containerBuilder, $content);
Expand All @@ -93,11 +90,6 @@ public function createAndLoadContainerBuilderFromFileInfo(

private function createLoaderBySuffix(ContainerBuilder $containerBuilder, string $suffix): DelegatingLoader
{
if ($suffix === Format::XML) {
$idAwareXmlFileLoader = $this->idAwareXmlFileLoaderFactory->createFromContainerBuilder($containerBuilder);
return $this->wrapToDelegatingLoader($idAwareXmlFileLoader, $containerBuilder);
}

if (in_array($suffix, [Format::YML, Format::YAML], true)) {
$missingAutodiscoveryDirectoryTolerantYamlFileLoader = new MissingAutodiscoveryDirectoryTolerantYamlFileLoader(
$containerBuilder,
Expand Down
Loading

0 comments on commit 2321183

Please sign in to comment.