Skip to content
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

Add possibility to define namespace of Symfony Console Command #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add possibility to define namespace of Symfony Console Command #109

wants to merge 1 commit into from

Conversation

o5
Copy link
Contributor

@o5 o5 commented Apr 24, 2020

With this change you can easily set your own command namespace in NEON (commandNamespace), YAML (command_namespace). It's needful when you have more databases.

NEON

migrations:
    dir: %appDir%/../migrations # migrations base directory
    driver: pgsql
    dbal: nextras
    commandNamespace: migrations:database1

OUTPUT

$ bin/console
migrations
  migrations:database1:continue             Updates database schema by running all new migrations
  migrations:database1:create               Creates new migration file with proper name (e.g. 2015-03-14-130836-label.sql)
  migrations:database1:reset                Drops current database and recreates it from scratch

REF: #94 (comment)

@@ -16,12 +16,9 @@

class ResetCommand extends BaseCommand
{
/** @var string */
protected static $defaultName = 'migrations:reset';

Copy link
Contributor

Choose a reason for hiding this comment

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

Default name should not be removed, even if not used in configure() because it breaks lazy loading.

Also commands with custom name can support lazy loading. In case of contributte/console could be added service tag $service->addTag('console.command', 'custom:command:name'). Not sure about kdyby/console and symfony DI integrations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I wanted to not remove this static property but symfony-bundle test failed on a weird notice like "undefined index continue" in Symfony/Application.php.

I didn't know this is symfony "build-in feature" from v3.4.10 and I have the same opinion like https://twitter.com/Majkl578/status/1214523751603286016

Any ideas how to resolve it? I agree that breaking lazy loading is not good.

@mabar
Copy link
Contributor

mabar commented May 13, 2021

Sorry, bit forgot about that. Change of command name is supported directly by symfony/console CommandLoader. The actual implementation is DIC-specific, so usage depends on which integration you use. For symfony/dependency-injection it should be $service->tag('console.command', ['command' => 'namespaced:migrations:reset']). For others it should be quite similar.

So any change of nextras/migrations code should not be needed.

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

Successfully merging this pull request may close these issues.

2 participants