Coder Social home page Coder Social logo

enviroment configuration about config HOT 16 CLOSED

respect avatar respect commented on June 28, 2024
enviroment configuration

from config.

Comments (16)

henriquemoody avatar henriquemoody commented on June 28, 2024

I have suggested to @augustohp and @alganet some reserved words starting with @.
Something like

foo = 123
bar = 456
; With checking
@include[] = '/path/to/file.ini'
; Without checking
@-include[] = '/path/to/file.ini'

Thinking that this should overwrite the current variables with its values, it will solve part of the problem.

from config.

iannsp avatar iannsp commented on June 28, 2024

I dont like... sound as an metadata, I know. something like annotations in text file ;)

from config.

alganet avatar alganet commented on June 28, 2024

These environment settings are just a way to extend and mix containers. You have two or more containers and some of them can reuse and replace entries from one another.

This is actually possible with the current implementation. Something like:

MyProject
  \ - src
  | - test
  | - conf
    \ - production.ini
    | - development.ini
    | - jenkins.ini
    | - application.ini
    | - database.ini
    | - router.ini
  | - docs

So, the production.ini, development.ini and jenkins.ini files are configurations for environments. The database.ini and router.ini are application-specific. The application.ini file is an abstract container.

application.ini

posts_per_page = 30
lists_enabled = true
; ...

database.ini

[conn PDO]
dsn = [db_dsn]
user = [db_user]
pass = [db_pass]
[mapper Respect\Relational\Mapper]
db = [conn]
; ...

router.ini

[router Respect\Rest\Router]
; ...

production.ini

db_dsn = "mysql:host=my-production-host;dbname=my-production-db"
db_user = "myproduser"
db_pass = "myprodpass"

development.ini

db_dsn = "mysql:host=localhost;dbname=mydb"
db_user = null
db_pass = null

jenkins.ini

db_dsn = "sqlite::memory:"
db_user = null
db_pass = null

To use and mix those guys, you call:

$c = new Container();
$c->loadFile("conf/application.ini");
$c->loadFile("conf/router.ini");
$c->loadFile("conf/database.ini");
$c->loadFile("conf/production.ini"); //change this to change env

Also, I've been using a recursive container manifest like this on my own projects:

manifest.ini

[container Respect\Config\Container]
loadFile[] = "conf/application.ini"
loadFile[] = "conf/router.ini"
loadFile[] = "conf/database.ini"
loadFile[] = "conf/" ENVIRONMENT ".ini" ;Respect\Config can use constants.

And using it like:

define('ENVIRONMENT', getenv('MY_ENV_FROM_APACHE_CONF'));
$c = new Container('conf/manifest.ini');
$c = $c->container; //switch the meta-container for the real one.

I believe this is enough and the syntax doesn't look hacky. It's way more extensible than hacking the ini format to allow our own syntax sugar, but I'd like to hear your opinion. What do you think?

from config.

iannsp avatar iannsp commented on June 28, 2024

is a good pratice use differente files for different enviroments but some developers use all envs in a same file to avoid missing change something or avoid missing add something.
Well, as a Vi User(hehe) I can see more then one file in the same without change the tab but can work with a single file is important because the happypanda moments when u incurs in erros by missing

from config.

henriquemoody avatar henriquemoody commented on June 28, 2024

(Out)

Respect logo should be a Panda with a magic cube in the hands. (the idea of the cube was of @iannsp).

\o/

from config.

iannsp avatar iannsp commented on June 28, 2024

something like this http://www.flickr.com/photos/gabique/4849646010/, but strong instead of cute ;)

from config.

henriquemoody avatar henriquemoody commented on June 28, 2024

This panda do not appears to be "respectable", got it?
LOL

from config.

nickl- avatar nickl- commented on June 28, 2024

@henriquemoody This is ambiguous:

<?php

@include[] = '/path/to/file.ini'
; Without checking
@-include[] = '/path/to/file.ini'

They are not includes, agree? @alganet is on the right track with loadfile or you may consider import ala less/sass/css but don't confuse this with include and require.

from config.

iannsp avatar iannsp commented on June 28, 2024

besides I understand all point u guys show up here I still insist in the fact of having(or can have) all environments setting up in a single file.
Its because its easily maintainable, reduce the error by missing probability and, in the end, isn't a bad pratice on ant-pattern. Instead of it, is a common pratice.

I suggest someting like this as possible option:
[ENVIRONMENT DEV]
db_user = 'devuser'
[ENVIRONMENT LIVE]
db_user = 'liveuser'

If we establish some terms as reserved, defining ENVIROMENT as one of those, and make the necessary to support this exacly we support namespace(for example), I believe "YES, WE CAN"(sorry republicans, my bad)
thats is my 2 cents

from config.

augustohp avatar augustohp commented on June 28, 2024

That's is good discussion!

@iannsp idea is valid and I agree that we already have support for this environment-aware container (better than any other implementation I've seen), BUT @iannsp may have some kind of problem with the actual solution. If this is the case, presenting this problem would be probably something to happen next.

Apart from that, let me notice that if we support the "ENVIRONMENT" reserved word (and implementation) I am afraid we will be soon facing the need of a "extension of enviroments" just like Zend Framework does. Needless to say that it is something we will probably regret later on (see ZF2 issues on that).

Just in note, Symfony does something different. It has different files for each environment.

  • app.php for production
  • app_dev.php for development

from config.

alganet avatar alganet commented on June 28, 2024

Not tested, but I believe this is possible:

[development]
user = alganet

[production]
user = respect

account = [user]

Using:

const ENVIRONMENT = 'production';
$config  = parse_ini_file('config.ini');
$config += $config[ENVIRONMENT];
$container = new Container($config);
print $container->account; //respect

from config.

nickl- avatar nickl- commented on June 28, 2024

Are you pondering what I'm pondering?

from config.

nickl- avatar nickl- commented on June 28, 2024

completed EnviromentConfigurationTest

from config.

alganet avatar alganet commented on June 28, 2024

Yay awesome 🐼

from config.

augustohp avatar augustohp commented on June 28, 2024

@nickl- You are awesome!

from config.

henriquemoody avatar henriquemoody commented on June 28, 2024

🐼

from config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.