Skip to content

Commit

Permalink
unprefix extension classes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 15, 2024
1 parent 4f790f1 commit 5936b5b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
11 changes: 11 additions & 0 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ function (string $filePath, string $prefix, string $content): string {
return Strings::replace($content, $pattern, 'public const $1 = \'');
},

function (string $filePath, string $prefix, string $content): string {
/** @see \Symplify\ConfigTransformer\Enum\SymfonyClass */
if (! str_ends_with($filePath, 'src/Enum/SymfonyClass.php')) {
return $content;
}

$pattern = sprintf('#public const (.*?) = \'%s\\\\\\\\#', $prefix);

return Strings::replace($content, $pattern, 'public const $1 = \'');
},

// unprefix strings class, used for node factory
// fixes https://github.com/symplify/symplify/issues/3976
function (string $filePath, string $prefix, string $content): string {
Expand Down
11 changes: 6 additions & 5 deletions src/Console/Command/GenerateConfigClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symplify\ConfigTransformer\Enum\SymfonyClass;

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',
SymfonyClass::DOCTRINE_EXTENSION,
SymfonyClass::MONOLOG_EXTENSION,
SymfonyClass::SECURITY_EXTENSION,
SymfonyClass::TWIG_EXTENSION,
SymfonyClass::DOCTRINE_EXTENSION,
];

private SymfonyStyle $symfonyStyle;
Expand Down
33 changes: 33 additions & 0 deletions src/Enum/SymfonyClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Symplify\ConfigTransformer\Enum;

final class SymfonyClass
{
/**
* @var string
*/
public const FRAMEWORK_EXTENSION = 'Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension';

/**
* @var string
*/
public const MONOLOG_EXTENSION = 'Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension';

/**
* @var string
*/
public const SECURITY_EXTENSION = 'Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension';

/**
* @var string
*/
public const TWIG_EXTENSION = 'Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension';

/**
* @var string
*/
public const DOCTRINE_EXTENSION = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension';
}

0 comments on commit 5936b5b

Please sign in to comment.