Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Impossible to use dotenv with this bundle #80

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 1 commit into from
Closed

Impossible to use dotenv with this bundle #80

wants to merge 1 commit into from

Conversation

grifx
Copy link

@grifx grifx commented Mar 14, 2018

There is a catch 22 with the new env(int:VAR) syntax. (https://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables)

Basically values are resolved at runtime. At compile-time it's a string, not integer, array or boolean. Which means we should have a loose validation.
symfony/symfony#23888

Fabien potencier has done a similar PR for swiftmailer: https://github.com/symfony/swiftmailer-bundle/pull/180/files#diff-850942b3ba24ab03a40aaa81b6152852L130

Cheers

There is a catch 22 with the new env(int:VAR) syntaxe. (https://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables)

Basically values are resolved at runtime. At compile-time it's a string, not integers array or boolean, which means we should have a loose validation.
symfony/symfony#23888

Fabien potencier has done PR for swiftmailer: https://github.com/symfony/swiftmailer-bundle/pull/180/files#diff-850942b3ba24ab03a40aaa81b6152852L130

Cheers
@Algatux
Copy link
Owner

Algatux commented Mar 15, 2018

Hi @grifx ! Thanks for your pr!
I will check it asap, can you write here a way to reproduce the issue so I can do a couple of tests against it ?

Thanks again!

@grifx
Copy link
Author

grifx commented Mar 15, 2018

Hi @Algatux,

.env

DATABASE__INFLUXDB__UDP_PORT="8086"

app.php

use Symfony\Component\Dotenv\Dotenv;

$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');

config.yml

influx_db:
    (...)
        udp_port:  '%env(int:DATABASE__INFLUXDB__UDP_PORT)%'

The symfony config component doesn't get an integer as value for udp_port as one may think but a string that is resolved as an integer at runtime.

Thanks for your work.

Cheers,

@Algatux
Copy link
Owner

Algatux commented Mar 15, 2018

@grifx, thx for these info, I will try asap!

@Algatux
Copy link
Owner

Algatux commented Mar 23, 2018

@grifx I think that we need to add a validation before creating the Database Instance using ports as 'strings'.

\Algatux\InfluxDbBundle\Services\ConnectionFactory::createConnection uses the config to initialize a new \InfluxDB\Database but is typehinted, this can lead to type errors if you are not casting the env var as int

@grifx
Copy link
Author

grifx commented Mar 25, 2018

@Algatux You are right "this can lead to type errors if you are not casting the env var as int".

I should have made it clear that this PR is a temporary fix.
The root of the problem is being solved at the Configuration component level: symfony/symfony#23888

What we can do is to remove the typing in ConnectionFactory::createConnection and throw a verbose exception if the ports provided aren't integers.

@Algatux
Copy link
Owner

Algatux commented Mar 26, 2018

@grifx Maybe a better solution can be a validation placed inside InfluxDbExtension::createConnection where we can simpli check that ports are numeric values and then cast them, otherwise an exception is thrown ... something like that IMHO

@grifx
Copy link
Author

grifx commented Mar 26, 2018

@Algatux Happy to do this. I thought you would be against it since a decision was made to enforce the types in the current implementation.

@Algatux
Copy link
Owner

Algatux commented Mar 26, 2018

@grifx I would like only to mantain the type hints on the methods

@Algatux
Copy link
Owner

Algatux commented Jul 6, 2018

@grifx any new about this pr ?

@soullivaneuh
Copy link
Collaborator

The options are booleans and integers. There is strictly nothing to fix here.

We are not responsible of the dotenv integration, Symfony is. This was "fixed" in Symfony 4.1. So you have only two solution: Upgrade to 4.1 or keep on parameters.yaml method waiting the upgrade,

@Algatux This PR should not be accepted.

@Algatux
Copy link
Owner

Algatux commented Jul 6, 2018

@soullivaneuh didn't know that the problem was fixed. I'm closing this pr, there is no more need for a temporary workaround. Thanks

@Algatux Algatux closed this Jul 6, 2018
@soullivaneuh
Copy link
Collaborator

@Algatux It is, but not for Symfony 3.4. I don't know why they did this like this, but is not our responsibility to fix an issue from a new feature not correctly setup on a vendor, IMHO. ;-)

@grifx
Copy link
Author

grifx commented Jul 10, 2018

Sorry, I forgot about this PR.

Options are booleans and integers but this is a Symfony Bundle. It's the responsibility of the bundle to make the setup process as smooth as possible for members of this ecosystem.

It doesn't seem a lot of people are complaining so there is probably no need for it.

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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.