Skip to content

Commit 8d7757c

Browse files
committed
1.1.0
1 parent 2e44721 commit 8d7757c

27 files changed

+230
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All Notable changes to `Vars` will be documented in this file
44

5+
## 1.1.0 - 2016-02-05
6+
7+
### Added
8+
- Support for `_globals`
9+
- Support to merge globals into `$app` for Silex
10+
511
## 1.0.0 - 2016-01-19
612

713
### Added

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Sometimes you're forced to use different formats for config files and one of Var
5959
by supporting the most common config formats so you don't have to switch libraries to deal with the different formats.
6060

6161
Another aim is to support different frameworks so again you don't have to switch libraries when dealing with different frameworks.
62-
Currently only supporting Silex with support for Laravel and Symfony to follow shortly.
62+
Currently only supporting Silex using a service provider, support for Laravel and Symfony to follow shortly.
6363

6464
With a simple API and intuitive loading options, Vars tries to make config loading and providing as easy as possible for you.
6565

@@ -293,6 +293,9 @@ $vars = new Vars(__DIR__.'/config/config.yml', [
293293
'foo' => 'bar',
294294
'foobar' => 'barfoo'
295295
],
296+
297+
// Merge globals -- see globals section for more detail
298+
'merge_globals' => true,
296299
297300
// The file loaders to load the configs -- see loader section for more detail
298301
'loaders' => [
@@ -465,6 +468,38 @@ Will be accessed by:
465468
getenv('test_key_1.test_key_2'); // value
466469
```
467470

471+
#### Globals
472+
473+
`Globals` in `Vars` refer to variables defined as such:
474+
475+
```yaml
476+
_globals:
477+
test_key_1: test_value_1
478+
```
479+
480+
Basically they are just encapsulated in an `_globals` array -- the use of these are so you can access them from `getGlobals()` from `Vars`
481+
482+
The default action is to merge them into the other file contents, so that:
483+
484+
```yaml
485+
_globals:
486+
test_key_1: test_value_1
487+
test_key_2: test_value_2
488+
```
489+
490+
Becomes:
491+
```php
492+
[
493+
'test_key_1' => 'test_value_1',
494+
'test_key_2' => 'test_value_2',
495+
]
496+
```
497+
But you can override this by changing `merge_globals` to `false` via the options.
498+
499+
If this doesn't make sense then you probably won't need to use globals at all, but they're useful for working with framesworks
500+
which encapsulate everything under say `$app` and you want to be able to access some key => values like so: `$app['test_key_1']`.
501+
See the Silex provider section for more examples.
502+
468503
#### Caching
469504

470505
Vars automatically caches the resources for 5 minutes, you can turn this off by setting the `cache` option to `false`.
@@ -554,7 +589,7 @@ $vars = new Vars(__DIR__.'/config/config.yml', [
554589

555590
It's pretty straightforward to use this library with Silex, just register it when you register other service providers:
556591
```php
557-
$app->register(new M1\Vars\Provider\Silex\VarsServiceProvider(__DIR__.'/../../app/config/example.yml'), [
592+
$app->register(new M1\Vars\Provider\Silex\VarsServiceProvider('example.yml'), [
558593
'vars.path' => __DIR__.'/../../app/config/test/',
559594
'vars.options' => [
560595
'cache' => true,
@@ -567,6 +602,7 @@ $app->register(new M1\Vars\Provider\Silex\VarsServiceProvider(__DIR__.'/../../ap
567602
'yml',
568603
'json'
569604
],
605+
'merge_globals' => true,
570606
'replacements' => __DIR__.'/../../app/config/replacements.json',
571607
]]);
572608
```
@@ -588,6 +624,31 @@ $app['vars']['test_key_1.test_key_2']; // value
588624
$app['vars']['test_key_3']; // value
589625
```
590626

627+
You can also merge globals into `$app` like so:
628+
629+
```yaml
630+
# example.yml
631+
_globals:
632+
monolog.logfile: log.log
633+
test_key_1: test_value_2
634+
```
635+
636+
```php
637+
$app->register(new M1\Vars\Provider\Silex\VarsServiceProvider('example.yml'));
638+
639+
// register monolog here and other service providers
640+
641+
$app['vars.merge']();
642+
```
643+
644+
Note the `$app['vars.merge']()` -- This overrides the service provider defaults so in this example `monolog` will use
645+
the log file defined in the vars config.
646+
647+
You must call `vars.merge` after you've called the service providers you provide config values for in your config.
648+
649+
You can also access `test_key_1` via `$app['vars.test_key_1']` and similary if you want, you can access globals like so
650+
`$app['monolog.logfile']`.
651+
591652
## Public API
592653

593654
### Vars
@@ -694,6 +755,9 @@ $vars->toDots();
694755
# ]
695756
```
696757

758+
##### `getGlobals()`
759+
760+
Gets the values defined in `_globals`
697761

698762
##### `set($key, $value)`
699763
Set a config key:

src/Cache/CacheProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/AbstractLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/DirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/EnvLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/IniLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/JsonLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/LoaderProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

src/Loader/PhpLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*
1111
* @package m1/vars
12-
* @version 1.0.0
12+
* @version 1.1.0
1313
* @author Miles Croxford <hello@milescroxford.com>
1414
* @copyright Copyright (c) Miles Croxford <hello@milescroxford.com>
1515
* @license http://github.com/m1/vars/blob/master/LICENSE

0 commit comments

Comments
 (0)