propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

Confusion between --connection and referring to which connection config to use #874

Open farhanrahman opened 9 years ago

farhanrahman commented 9 years ago

So from the gitter chat earlier today @Celc discovered a case where trying to access a connection config using the flag --connection results in an error. The yaml configuration file looks like this:

propel:
    database:
        connections:
            default:
                adapter: mysql
                dsn: mysql:host=localhost;dbname=some_db
                user: root
                password:
                settings:
                    charset: utf8
            staging:
                adapter: mysql
                dsn: mysql:host=staging_host;dbname=some_db
                user: some_username
                password: some_password
                settings:
                    charset: utf8
    generator:
        defaultConnection: default
        connections:
            - default
    runtime:
        defaultConnection: default
        connections:
            - default

In AbstractCommand the parseConnection method (https://github.com/propelorm/Propel2/blob/master/src/Propel/Generator/Command/AbstractCommand.php#L118) returns a connection with $name as an empty string.

The problem with this happens in trying to finalize the configuration in Symphony's Processor in here

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Config/Definition/Processor.php#L37

I need to dig into Propel's tree builder to know more about this issue. Either way I think it will be better to distinguish between --connection as a dsn and --connection as a configuration from the yaml/json/* file. Perhaps something like --connection_config=default/staging. Moreover it might be better to put a regexp for the connection to alert the user that the connection format is wrong.

marcj commented 9 years ago

Yes, we have in database:reserver command already some code which makes it possible to pass for --connection a connection name or a dsn. https://github.com/propelorm/Propel2/blob/master/src/Propel/Generator/Command/DatabaseReverseCommand.php#L60

Although DatabaseReserve is a bit different than others, we should make everywhere possible to use a connection name or a dsn, which will be auto detected then like in database:reserve.