yiisoft / config

Configuration management
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
31 stars 11 forks source link

Support for environment groups in vendor package? #137

Closed tomaszkane closed 6 months ago

tomaszkane commented 1 year ago

What steps will reproduce the problem?

Define config file for given environment, like "dev", "prod" etc. https://github.com/yiisoft/config#environments but in composer.json located in vendor directory.

What is the expected result?

For vendor composer like:

"extra": {
    "config-plugin-options": {
      "source-directory": "config"
    },
    "config-plugin": {
      "yii2-api": "yii2-api.php"
    },
    "config-plugin-environments": {
      "dev": {
        "yii2-api": [
          "$yii2-api",
          "dev/yii2-api.php"
        ]
      },
      "prod": {
        "yii2-api": [
          "$yii2-api",
          "prod/yii2-api.php"
        ]
      }
    }
  },

Config called in root project return dev configs also from "vendors".

$yiiConfig = new Config(
    paths: new ConfigPaths(__DIR__),
    environment: 'dev',
);
$yiiConfig->get('yii2-api');

What do you get instead?

Environment config from "vendor" projects (repositories/packages) is not present in .merge-plan.

Additional info

I develop a project-template based on Yii2 who's using several packages via composer and want to have all configs of this packages in package repository - thanks to that composer install/update will fully configure my application. Some of my packeges sohuld use different params/configs based on environemtns, like: disable "https / secure" in dev and test environments. Set "sandbox" or "production" to payment-provide package etc.

It's possible to achieve that? Or how to do it better/different?

Q A
Version 1.3.0
PHP version 8.0
Operating system KDE Neon
tomaszkane commented 1 year ago

Please update a README with something like: "This works only for main/root/business composer.json file." https://github.com/yiisoft/config#environments

vjik commented 1 year ago

@tomaszkane I created PR with note.


Seems, this case is valid. Packages may be related to application layer. Add ability set environments in such packages looks as good idea. I think, we can add environments support to packages from vendor-override-layer, but not to all packages.


Now you can try use so approach to resolve your task:

"extra": {
    "config-plugin-options": {
      "source-directory": "config"
    },
    "config-plugin": {
      "yii2-api": "yii2-api.php",
      "yii2-api-prod": "prod/yii2-api.php",
      "yii2-api-dev": "dev/yii2-api.php",
    },
  },
"extra": {
    "config-plugin-environments": {
      "dev": {
        "yii2-api": [
          "$yii2-api-dev",
          "dev/yii2-api.php"
        ],
      },
      "prod": {
        "yii2-api": [
          "$yii2-api-prod",
          "prod/yii2-api.php"
        ]
      }
    }
  },
rustamwin commented 1 year ago

Could you try with:

"config-plugin": {
      "di": "yii2-api.php"
    },
    "config-plugin-environments": {
      "dev": {
        "di": [
          "$di",
          "dev/yii2-api.php"
        ]
      },
      "prod": {
        "di": [
          "$di",
          "prod/yii2-api.php"
        ]
      }
    }

?

tomaszkane commented 6 months ago

I think it works for me. Thanks.