Comments (16)
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.
I dont like... sound as an metadata, I know. something like annotations in text file ;)
from config.
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.
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.
(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.
something like this http://www.flickr.com/photos/gabique/4849646010/, but strong instead of cute ;)
from config.
This panda do not appears to be "respectable", got it?
LOL
from config.
@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.
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.
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 productionapp_dev.php
for development
from config.
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.
from config.
completed EnviromentConfigurationTest
from config.
Yay awesome 🐼
from config.
@nickl- You are awesome!
from config.
🐼
from config.
Related Issues (20)
- Instantiator should not implement __invoke() HOT 3
- Variable references inside sequences may not be working HOT 6
- Lazy loading not working for parameters HOT 3
- Support for builders HOT 3
- Treat unset variables as parameters + Cross-container communication HOT 3
- Prevent InvalidArgumentException to optional arguments HOT 5
- Include/Import config HOT 4
- Add composer in the README.md HOT 1
- 100% Code coverage HOT 3
- Wrong tags HOT 2
- Constant evaluation HOT 1
- Support for Type Hinting HOT 2
- I dont want expand my password HOT 2
- Reusing lazyLoaded instances bug
- Matching namespaced references HOT 3
- ContainerInterop implementation
- Instantiator Improvements
- Object with underline not parsed correctly HOT 1
- Instantiator not able to resolve __constructor with alone argument HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.