Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentscheffler committed Aug 21, 2019
0 parents commit 945b76e
Show file tree
Hide file tree
Showing 14 changed files with 3,751 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root=true

[*]
end_of_line=lf
indent_style=tab
indent_size=4
charset=utf-8
trim_trailing_whitespace=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
build/
.phpunit.result.cache
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
php:
- '7.2'

install:
- composer install

script:
- make coverage

after_success:
- travis_retry php vendor/bin/php-coveralls
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: release

test:
vendor/bin/phpunit

coverage:
vendor/bin/phpunit --coverage-clover=build/logs/clover.xml

analyze:
vendor/bin/psalm

release:
/usr/bin/env php release
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Config

A simple configuration manager with lazy loading from files.

## Installation

```bash
composer require nimbly/config
```

## Configuration files

Configuration files should return an associative array with the settings of your choice.

```php
<?php

return [
"host" => "localhost",
"port" => 1234,
"user" => "dbuser",
"password" => "dbpassword",
];
```

## Usage

Instantiate the ```Config``` manager with the location on disk to your configuration files.

```php
$config = new Config(__DIR__ . "/config");
```

## Accessing values

Configuration keys can be accessed using a dot-notation syntax with the left most being the root file name of the configuration file.

```php
$config->get('database.host');
```

The above would load the contents of the file ```database.php``` from the configuration path passed into the ```Config``` manager.

Your configuration files may contain nested associative arrays that can be accessed using the same dotted notation.

```php
$config->get("database.connections.default.host");
```

## Default values

When getting keys from the config manager, you can optionally define a default value.

```php
$config->get('database.host', 'localhost');
```

## Manually adding values

You may also manually add new key / value pairs into the configuration manager.

```php
$config->add('queue', [
'name' => 'jobs',
'host' => 'localhost',
'port' => 1234
]);
```
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "nimbly/config",
"description": "Configuration and settings manager with autoloading from disk.",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^8.3",
"vimeo/psalm": "^3.4",
"symfony/var-dumper": "^4.3",
"php-coveralls/php-coveralls": "^2.1"
},
"license": "MIT",
"authors": [
{
"name": "Brent Scheffler",
"email": "brent@brentscheffler.com"
}
],
"require": {
"php": ">=7.2"
},
"autoload": {
"psr-4": {
"nimbly\\Config\\": "src\/"
}
}
}
Loading

0 comments on commit 945b76e

Please sign in to comment.