gacela-project / gacela

Build modular PHP applications.

Home Page:http://gacela-project.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gacela configuration for different envs (gacela-test.php)

JesusValera opened this issue Β· comments

issue related to this discussion: https://github.com/gacela-project/gacela/discussions/88

πŸ“š Description

Currently, the Gacela configuration is on the gacela.php file, on this file we are able to define the mapping interfaces on the mappingInterfaces() method, the problem we can face is we want to define certain interface (e.g: Logger or DB) on production, but on a feature test we just want to use mocks/spies for those interfaces.
With this scenario, it would be interesting to be able to define another gacela-{$env}.php file for this purpose.

The question is:
Should be allow to define only for testing environment (gacela-test.php) OR any environment.

I wouldn't limit this feature to be only for "testing environments", because what are "testing environments"? I would simply allow any env: gacela-{$env}.php, and the APP_ENV will rule them all.

I'm obviously still new to Gacela...

Looking at this... it looks like there is a constant set in:

private const GACELA_PHP_CONFIG_FILENAME = 'gacela.php';

So can we make this constant a configurable value like we do here:

https://github.com/gacela-project/gacela-example/blob/77d4cd2a02809b1b0e80f291cdd136a48aa48943/using-custom-config/src/CustomConfigExample/Config.php#L13

Then what about fallback if a custom ENV variable is not present in the config?

@webcraftniray yes, the constant gacela.php you mention is the first thing you should change in order to achieve this ticket.
The idea is the gacela-dev.php should override the gacela.php file (if both files exists and we are in dev environment).

One suggestion @Chemaclass, if we are in dev environment and we have the following files:

  1. gacela.php
  2. gacela-prod.php
  3. gacela-dev.php

A) Load all files and finally override with the environment file?

B) Load only the gacela.php and depending on the environment if this file exists, override with this configuration?
In this scenario, we load first gacela.php and finally gacela-dev.php.

I think the option B makes more sense, what do you think? πŸ˜„


Regarding your last question @webcraftniray, if the key is not present in gacela.php either in gacela-dev.php, it should thrown an exception (unless you define a fallback value), see https://github.com/gacela-project/gacela/blob/master/src/Framework/Config.php#L65

I think you are mixing two concepts. Config key-values and gacela.php.

I think this could be a bit tricky issue. I would suggest starting with a Good first issue first :)

I would like to take this issue.