@@ -59,7 +59,7 @@ Sometimes you're forced to use different formats for config files and one of Var
5959by supporting the most common config formats so you don't have to switch libraries to deal with the different formats.
6060
6161Another 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
6464With 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:
465468getenv('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
470505Vars 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
555590It'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\V ars\P rovider\S ilex\V arsServiceProvider(__DIR__.'/../../app/config/ example.yml'), [
592+ $app->register(new M1\V ars\P rovider\S ilex\V arsServiceProvider(' 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\V ars\P rovider\S ilex\V arsServiceProvider('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)`
699763Set a config key :
0 commit comments