symfony / flex

Composer plugin for Symfony
MIT License
4.16k stars 183 forks source link

Flex 1.2 / dump-env command and existing environment variables #475

Closed ipernet closed 5 years ago

ipernet commented 5 years ago

Hi,

$ cat .env|wc -l
101

$ composer dump-env dev && cat .env.local.php 
Successfully dumped .env files in .env.local.php
<?php

// This file was generated by running "composer dump-env dev"

return array (
  'APP_ENV' => 'dev',
);

In the execution context of the composer dump-env dev command, all my env variables in my .env file are in fact already sourced (already present as env variables).

I would expect the dump-env command to not be impacted by what variables are already set in the env and just dump whatever is in .env* to .env.local.php. Otherwise it leads to unexpected results (empty or partial env cache file generated).

Is that my mistake to have such env variables already sourced or is it an unexpected behavior of dump-env, or both ?

Thanks!

nicolas-grekas commented 5 years ago

It should be fixed, that's not desired! Would you like to give it a try?

ipernet commented 5 years ago

Hi @nicolas-grekas

What dependency has been updated or should I manually update to test?

Here is what I have, with no updates available:

$ composer show symfony/*

symfony/asset                v4.2.3  Symfony Asset Component
symfony/browser-kit          v4.2.3  Symfony BrowserKit Component
symfony/cache                v4.2.3  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.3  Symfony Config Component
symfony/console              v4.2.3  Symfony Console Component
symfony/contracts            v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector         v4.2.3  Symfony CssSelector Component
symfony/debug                v4.2.3  Symfony Debug Component
symfony/debug-bundle         v4.2.3  Symfony DebugBundle
symfony/debug-pack           v1.0.7  A debug pack for Symfony projects
symfony/dependency-injection v4.2.3  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.3  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.3  Symfony DomCrawler Component
symfony/dotenv               v4.2.3  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.3  Symfony EventDispatcher Component
symfony/expression-language  v4.2.3  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.3  Symfony Filesystem Component
symfony/finder               v4.2.3  Symfony Finder Component
symfony/flex                 v1.2.0  Composer plugin for Symfony
symfony/form                 v4.2.3  Symfony Form Component
symfony/framework-bundle     v4.2.3  Symfony FrameworkBundle
symfony/http-foundation      v4.2.3  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.3  Symfony HttpKernel Component
symfony/inflector            v4.2.3  Symfony Inflector Component
symfony/intl                 v4.2.3  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle         v1.11.3 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/monolog-bridge       v4.2.3  Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1  Symfony MonologBundle
symfony/options-resolver     v4.2.3  Symfony OptionsResolver Component
symfony/orm-pack             v1.0.6  A pack for the Doctrine ORM
symfony/panther              v0.2.0  A browser testing and web scraping library for PHP and Symfony.
symfony/phpunit-bridge       v4.2.3  Symfony PHPUnit Bridge
symfony/polyfill-intl-icu    v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process              v4.2.3  Symfony Process Component
symfony/profiler-pack        v1.0.4  A pack for the Symfony web profiler
symfony/property-access      v4.2.3  Symfony PropertyAccess Component
symfony/property-info        v4.2.3  Symfony Property Info Component
symfony/routing              v4.2.3  Symfony Routing Component
symfony/security-bundle      v4.2.3  Symfony SecurityBundle
symfony/security-core        v4.2.3  Symfony Security Component - Core Library
symfony/security-csrf        v4.2.3  Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.3  Symfony Security Component - Guard
symfony/security-http        v4.2.3  Symfony Security Component - HTTP Integration
symfony/serializer           v4.2.3  Symfony Serializer Component
symfony/serializer-pack      v1.0.2  A pack for the Symfony serializer
symfony/stopwatch            v4.2.3  Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.5  Symfony SwiftmailerBundle
symfony/templating           v4.2.3  Symfony Templating Component
symfony/test-pack            v1.0.5  A pack for functional and end-to-end testing within a Symfony app
symfony/translation          v4.2.3  Symfony Translation Component
symfony/twig-bridge          v4.2.3  Symfony Twig Bridge
symfony/twig-bundle          v4.2.3  Symfony TwigBundle
symfony/validator            v4.2.3  Symfony Validator Component
symfony/var-dumper           v4.2.3  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.3  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle  v4.2.3  Symfony WebProfilerBundle
symfony/yaml                 v4.2.3  Symfony Yaml Component
nicolas-grekas commented 5 years ago

symfony/flex 1.2

nicolas-grekas commented 5 years ago

That's something we should take care of in https://github.com/symfony/flex/blob/master/src/Command/DumpEnvCommand.php

ipernet commented 5 years ago

That is the merge request I would suggest to improve and fix loadEnv() with the case I have.

Once implemented, dump-env could call loadEnv() from:

$dotenv->loadEnv($path);

to

$dotenv->loadEnv($path, 'APP_ENV', 'dev', ['test'], true);

or use any optional command-line argument to ask for the overload.

The overloading of variables is however not supported before DotEnv 4.2