Skip to content

Instantiate ConfigurationLoaderFactory when not in container #142

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

Conversation

scottasmith
Copy link
Contributor

@scottasmith scottasmith commented Nov 12, 2024

Allow multi-connection based migration other than just orm_default. This is useful if the migrations tables need to exist in multiple different databases or schemas.

e.g.

Config

    'doctrine' => [
        ...
        'migrations' => [
            'orm_default' => [...],
            'orm_other_connection' => [...],
        ],
        ...
    ],

bin/doctrine

$input = new ArgvInput();

/** @var string $em */
$em = $input->getParameterOption('--em', 'orm_default');


// hack to remove the --em option, cause it's not supported by the original ConsoleRunner.
foreach ($_SERVER['argv'] as $i => $arg) {
    if (str_starts_with($arg, '--em=')) {
        unset($_SERVER['argv'][$i]);
    }
}

try {
    $entityManager = $container->get('doctrine.entity_manager.' . $em);
} catch (NotFoundExceptionInterface $serviceNotFoundException) {
    throw new InvalidArgumentException(sprintf('Missing entity manager with name "%s"', $em));
}

$commandFactory = new CommandFactory($em);

$commands = [
    $commandFactory($container, Command\CurrentCommand::class),
    ...
];

...

@Slamdunk
Copy link
Collaborator

I'm staring at the code and can't figure out why we haven't done $configurationLoader = (new ConfigurationLoaderFactory($configKey))($container); since the beginning 🤔

Overall looks good, but I'd like you to extend the README.md to include when and how to leverage this new feature

@scottasmith
Copy link
Contributor Author

Overall looks good, but I'd like you to extend the README.md to include when and how to leverage this new feature

Thanks @Slamdunk. I have updated the README.md

@Slamdunk Slamdunk added this to the 5.5.0 milestone Nov 13, 2024
@Slamdunk Slamdunk added the enhancement New feature or request label Nov 13, 2024
@Slamdunk Slamdunk merged commit 5db2b96 into Roave:5.5.x Nov 13, 2024
10 checks passed
@scottasmith scottasmith deleted the make-dependency-factory-factory-more-dynamic branch November 13, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants