Comments (2)
Actually, the usage is a little bit different. Each [section] creates a new object or array, and variable expanding works only for variables outside sections. I would probably write something like this:
pdo_driver = "mysql"
pdo_host = "localhost"
pdo_name = "somedb"
pdo_user = "root"
pdo_pass = ""
pdo_dsn = "[pdo_driver]:host=[pdo_host];dbname=[pdo_name]"
mongo_driver = "mongodb"
mongo_host = "localhost"
mongo_name = "something"
mongo_user = "user"
mongo_pass = "pass"
mongo_server = "[mongo_driver]://[mongo_user]:[mongo_pass]@[mongo_host]"
[pdoConnection PDO]
dsn = [pdo_dsn]
username = [pdo_user]
password = [pdo_pass]
[mongoConnection Mongo]
server = [mongo_server]
[mongoDb MongoDb]
conn = [mongoConnection]
And then:
<?php
$container = new Respect\Config\Container("config.ini");
$mongoDb = $container->mongoDb;
$db = $container->pdoConnection;
In this sample, the keys outside sections acts as variables that you can use elsewhere. The [sections] represent objects, so [pdoConnection PDO] means $pdoConnection = new PDO. The keys for each section are parameters for that object. They can be constructor params, properties or method calls.
The PDO object for example has a constructor with the params $dsn, $username and $password. Respect\Config then uses the keys inside the config section to instantiate that object.
The usage is similar to PHP itself, but the main advantage is that every object declaration is lazy loaded. The PDO connection will only start when you try to get it from the container.
Let me know if I can help you with anything else. Thanks!
from config.
thanks! :)
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
- enviroment configuration HOT 16
- 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.