Skip to content

Use DSN-like strings to define credentials #572

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ doctrine:
dbal:
# if you don't want to use SQLite, change the URL in parameters.yml or set the DATABASE_URL environment variable
url: '%env(DATABASE_URL)%'

# instead of using a URL, you may also uncomment the following lines to configure your database
# driver: pdo_mysql
# host: '%database_host%'
# port: '%database_port%'
# dbname: '%database_name%'
# user: '%database_user%'
# password: '%database_password%'
# charset: UTF8

orm:
auto_generate_proxy_classes: '%kernel.debug%'
auto_mapping: true
Expand All @@ -83,8 +73,5 @@ doctrine:
# stores options that change from one server to another
#
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
url : '%env(MAILER_URL)%'
spool: { type: memory }
8 changes: 0 additions & 8 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ web_profiler:
# swiftmailer:
# disable_delivery: true

# It's recommended to use a separate database for tests. This allows to have a
# fixed and known set of data fixtures, it simplifies the code of tests and it
# makes them more robust.
# In this case we just need to define a different path for the application database.
doctrine:
dbal:
path: "%kernel.project_dir%/var/data/blog_test.sqlite"

# this configuration simplifies testing URLs protected by the security mechanism
# See https://symfony.com/doc/current/cookbook/testing/http_authentication.html
security:
Expand Down
7 changes: 2 additions & 5 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters:
# this demo application uses an embedded SQLite database to simplify setup.
# in a real Symfony application you probably will use a MySQL or PostgreSQL database
# the path must be relative or else it will not work on Windows
env(DATABASE_URL): 'sqlite:///%kernel.project_dir%/var/data/blog.sqlite'
env(DATABASE_URL): 'sqlite://%kernel.project_dir%/var/data/blog.sqlite'

# Uncomment this line to use a MySQL database instead of SQLite (and remove
# the "doctrine" section from config_dev.yml regarding SQLite):
Expand All @@ -33,7 +33,4 @@ parameters:

# If you don't use a real mail server, you can send emails via your Gmail account.
# see https://symfony.com/doc/current/cookbook/email/gmail.html
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
env(MAILER_URL): 'smtp://localhost:25?encryption=&auth_mode='
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="app/" />
<env name="DATABASE_URL" value="sqlite://%kernel.project_dir%/var/data/blog_test.sqlite"/>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can use a parameter here, in an actual env var

Copy link
Contributor

@dmaicher dmaicher May 30, 2017

Choose a reason for hiding this comment

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

Actually you are right but it still works 😄

Really weird what happens now when dumping the connection within a test to see the config:

  -_params: array:9 [
    "url" => "sqlite://%kernel.project_dir%/var/data/blog_test.sqlite"
    "host" => "%kernel.project_dir%"
    "port" => null
    "user" => "root"
    "password" => null
    "driver" => "pdo_sqlite"
    "driverOptions" => []
    "defaultTableOptions" => []
    "path" => "var/data/blog_test.sqlite"
  ]

This seems to be more correct:

<env name="DATABASE_URL" value="sqlite:///var/data/blog_test.sqlite" />

==>

  -_params: array:9 [
    "url" => "sqlite:///var/data/blog_test.sqlite"
    "host" => "localhost"
    "port" => null
    "user" => "root"
    "password" => null
    "driver" => "pdo_sqlite"
    "driverOptions" => []
    "defaultTableOptions" => []
    "path" => "var/data/blog_test.sqlite"
  ]

Copy link
Contributor

Choose a reason for hiding this comment

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

@javiereguiluz FYI see above

Copy link
Member Author

@javiereguiluz javiereguiluz May 30, 2017

Choose a reason for hiding this comment

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

@dmaicher you are right. I fixed that in 464e786 but I think Christophe is right and container params don't work here. I partially fixed what you say ... but I'm going to test your full solution now. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

</php>

<testsuites>
Expand Down