Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Fix importing PHP configs in the prepend extension method #57937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Aug 6, 2024

Q A
Branch? 7.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #57936
License MIT

I missed this nesting case during #52843.

@nicolas-grekas
Copy link
Member

Thank you @yceruto.

@nicolas-grekas nicolas-grekas merged commit 5abfba2 into symfony:7.1 Aug 7, 2024
9 of 10 checks passed
@@ -92,6 +92,7 @@ public function import(mixed $resource, ?string $type = null, bool|string $ignor
}
} finally {
--$this->importing;
$this->loadExtensionConfigs();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this here (even in case of exception) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because there is a return statement inside the try block, so there is no other chance to load the collected ext config after --$this->importing; instruction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, it's not about the exception at all, but if it happens I guess it doesn't matter if we try to prepend some configs afterward

@yceruto yceruto deleted the bugfix_prepend_php_config branch August 7, 2024 14:33
@jfsenechal
Copy link

jfsenechal commented Aug 8, 2024

It doesn't work for more than one bundle

Only the last bundle is taken into account

bin/console doctrine:mapping:info
 Found 3 mapped entities:

 [OK]   AcMarche\Cap\Entity\Commercant
 [OK]   AcMarche\Cap\Entity\CommercantGallery
 [OK]   AcMarche\Cap\Entity\CommercioBottin

ABundle

class ABundle extends AbstractBundle
{
    public function getPath(): string
    {
        return \dirname(__DIR__);
    }

    public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import('../config/services.php');
    }

    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->import('../config/packages/doctrine.php');
    }
}
//doctrine.php
return static function (DoctrineConfig $doctrine) {
    $doctrine->dbal()
        ->connection('default')
        ->url(env('DATABASE_URL')->resolve());
    $em = $doctrine->orm()->entityManager('default');
    $doctrine->dbal()->defaultConnection('default');
    $em->connection('default');

    $em->mapping('AcMarcheBottin')
        ->isBundle(false)
        ->type('attribute')
        ->dir('%kernel.project_dir%/src/AcMarche/Bottin/src/Entity')
        ->prefix('AcMarche\Bottin')
        ->alias('AcMarcheBottin');
};

BBundle

class ABundle extends AbstractBundle
{
//...
//the same as above
}
//doctrine.php
return static function (DoctrineConfig $doctrine) {
    $doctrine->dbal()
        ->connection('cap')
        ->url(env('DATABASE_URL_CAP')->resolve());

    $em = $doctrine->orm()->entityManager('cap');
    $em->connection('cap');

    $em->mapping('AcMarcheCap')
        ->isBundle(false)
        ->type('attribute')
        ->dir('%kernel.project_dir%/src/AcMarche/Cap/src/Entity')
        ->prefix('AcMarche\Cap')
        ->alias('AcMarcheCap');
};

@yceruto
Copy link
Member Author

yceruto commented Aug 8, 2024

@jfsenechal can you open a new issue with details so I can take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants