Skip to content

Commit

Permalink
Added dot notation access to $app for the Silex service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
m1 committed Jan 8, 2016
1 parent b0b8457 commit 0ba6d78
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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

## 0.6.0 - 2016-01-08

### Added
- Added dot notation access to `$app` for the Silex service provider

## 0.5.0 - 2016-01-07

### Altered
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ Then you can access your config from `$app['vars']`

*Note: If you `$app['debug'] = true` then the cache will not be used.*

You can also access the config values from $app by using the dot notation, e.g:
```yaml
test_key_1:
test_key_2: value
test_key_3: value
```

You can get the above using the dot notation like so:
```php
$app['vars.test_key_1.test_key_2']; // value
$app['vars.test_key_3']; // value
```

## Public API

### Vars
Expand Down
6 changes: 6 additions & 0 deletions src/Provider/Silex/VarsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
class VarsServiceProvider implements ServiceProviderInterface
{
public $vars;

/**
* The entity to use Vars with
*
Expand Down Expand Up @@ -69,6 +71,10 @@ public function register(Application $app)
$app['vars'] = function ($app) {
return new Vars($this->entity, $this->createOptions($app));
};

foreach ($app['vars']->toDots() as $key => $value) {
$app['vars.'.$key] = $value;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/VarsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ public function testBasicSilexServiceProvider()
));

$this->assertEquals($this->basic_array, $app['vars']->getContent());

$this->assertEquals('test_value_1', $app['vars.test_key_1']);
}

public function testOptionsSilexServiceProvider()
Expand Down

0 comments on commit 0ba6d78

Please sign in to comment.