Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 599b984
Showing
12 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.json] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
vendor | ||
|
||
composer.lock | ||
coverage.xml | ||
.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
$header = <<<EOF | ||
This file is part of vaibhavpandeyvpz/kunfig package. | ||
(c) Vaibhav Pandey <contact@vaibhavpandey.com> | ||
This source file is subject to the MIT license that is bundled | ||
with this source code in the file LICENSE.md. | ||
EOF; | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
return Config::create() | ||
->setFinder( | ||
Finder::create() | ||
->in(__DIR__ . '/src') | ||
->in(__DIR__ . '/tests') | ||
) | ||
->setRules(array( | ||
'@PSR2' => true, | ||
'header_comment' => array('header' => $header), | ||
'array_syntax' => true, | ||
)) | ||
->setUsingCache(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
after_success: bash <(curl -s https://codecov.io/bash) | ||
|
||
before_install: travis_retry composer self-update | ||
|
||
branches: | ||
only: master | ||
|
||
cache: | ||
directories: $HOME/.composer/cache | ||
|
||
install: travis_retry composer install --dev --no-interaction --prefer-dist | ||
|
||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- hhvm | ||
|
||
script: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2016 Vaibhav Pandey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# vaibhavpandeyvpz/kunfig | ||
Helper library to easily merge & use multiple configuration files. | ||
|
||
[![Build status][build-status-image]][build-status-url] | ||
[![Code Coverage][code-coverage-image]][code-coverage-url] | ||
[![Latest Version][latest-version-image]][latest-version-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
[![PHP Version][php-version-image]][php-version-url] | ||
[![License][license-image]][license-url] | ||
|
||
[![SensioLabsInsight][insights-image]][insights-url] | ||
|
||
Install | ||
------- | ||
```bash | ||
composer require vaibhavpandeyvpz/kunfig | ||
``` | ||
|
||
Usage | ||
----- | ||
```php | ||
<?php | ||
|
||
/** | ||
* @desc Create a Kunfig\Config instance with some initial values | ||
* passed into constructor. | ||
*/ | ||
$config = new Kunfig\Config(array( | ||
'database' => array( | ||
'host' => 'localhost', | ||
'port' => 3306, | ||
'charset' => 'utf8mb4', | ||
), | ||
'debug' => false, | ||
)); | ||
|
||
// Get a value | ||
$host = $config->database->host; | ||
|
||
// Set a value | ||
$config->database->host = 'xxxxxxxxxxxxx.xxxxxxxxxxxxx.us-west-2.rds.amazonaws.com'; | ||
|
||
$override = new Kunfig\Config(array( | ||
'database' => array( | ||
'name' => 'test', | ||
'user' => 'root', | ||
'password' => null, | ||
), | ||
)); | ||
|
||
/** | ||
* @desc You can mix two Kunfig\ConfigInterface; the latter one | ||
* will override values in the original one. | ||
*/ | ||
$config->mix($override); | ||
|
||
$pdo = new PDO( | ||
"mysql:host={$config->database->host}:{$config->database->port};dbname={$config->database->name}", | ||
$config->database->user, | ||
$config->database->password | ||
); | ||
``` | ||
|
||
License | ||
------- | ||
See [LICENSE.md][license-url] file. | ||
|
||
[build-status-image]: https://img.shields.io/travis/vaibhavpandeyvpz/kunfig.svg?style=flat-square | ||
[build-status-url]: https://travis-ci.org/vaibhavpandeyvpz/kunfig | ||
[code-coverage-image]: https://img.shields.io/codecov/c/github/vaibhavpandeyvpz/kunfig.svg?style=flat-square | ||
[code-coverage-url]: https://codecov.io/gh/vaibhavpandeyvpz/kunfig | ||
[latest-version-image]: https://img.shields.io/github/release/vaibhavpandeyvpz/kunfig.svg?style=flat-square | ||
[latest-version-url]: https://github.com/vaibhavpandeyvpz/kunfig/releases | ||
[downloads-image]: https://img.shields.io/packagist/dt/vaibhavpandeyvpz/kunfig.svg?style=flat-square | ||
[downloads-url]: https://packagist.org/packages/vaibhavpandeyvpz/kunfig | ||
[php-version-image]: http://img.shields.io/badge/php-5.3+-8892be.svg?style=flat-square | ||
[php-version-url]: https://packagist.org/packages/vaibhavpandeyvpz/kunfig | ||
[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[license-url]: LICENSE.md | ||
[insights-image]: https://insight.sensiolabs.com/projects/2606a5ca-43c2-4db9-ba3f-007e13e31362/small.png | ||
[insights-url]: https://insight.sensiolabs.com/projects/2606a5ca-43c2-4db9-ba3f-007e13e31362 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"authors": [{ | ||
"name": "Vaibhav Pandey", | ||
"email": "contact@vaibhavpandey.com" | ||
}], | ||
"autoload": { | ||
"psr-4": { | ||
"Kunfig\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Kunfig\\": "src/" | ||
} | ||
}, | ||
"description": "Helper library to easily merge & use multiple configuration files.", | ||
"homepage": "http://vaibhavpandeyvpz.github.io/kunfig", | ||
"keywords": ["php", "multiple", "configuration", "manager"], | ||
"license": "MIT", | ||
"name" : "vaibhavpandeyvpz/kunfig", | ||
"require": { | ||
"php": "^5.3 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.0 || ^5.0" | ||
}, | ||
"type": "library" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<phpunit bootstrap="vendor/autoload.php" colors="true" verbose="true"> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-clover" target="coverage.xml" /> | ||
</logging> | ||
<testsuites> | ||
<testsuite name="vaibhavpandeyvpz/kunfig"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of vaibhavpandeyvpz/kunfig package. | ||
* | ||
* (c) Vaibhav Pandey <contact@vaibhavpandey.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE.md. | ||
*/ | ||
|
||
namespace Kunfig; | ||
|
||
/** | ||
* Class Config | ||
* @package Kunfig | ||
*/ | ||
class Config extends ConfigAbstract | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $values = array(); | ||
|
||
/** | ||
* Config constructor. | ||
* @param array $values | ||
*/ | ||
public function __construct(array $values = array()) | ||
{ | ||
foreach ($values as $key => $value) { | ||
$this->set($key, $value); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all() | ||
{ | ||
$values = array(); | ||
foreach ($this->values as $key => $value) { | ||
if ($value instanceof ConfigInterface) { | ||
$values[$key] = $value->all(); | ||
} else { | ||
$values[$key] = $value; | ||
} | ||
} | ||
return $values; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function count() | ||
{ | ||
return count($this->values); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($key) | ||
{ | ||
return array_key_exists($key, $this->values); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($key, $fallback = null) | ||
{ | ||
return $this->has($key) ? $this->values[$key] : $fallback; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new \ArrayIterator($this->values); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function mix(ConfigInterface $config) | ||
{ | ||
foreach ($config as $key => $value) { | ||
if ($this->has($key)) { | ||
$preset = $this->get($key); | ||
if (($preset instanceof ConfigInterface) && ($value instanceof ConfigInterface)) { | ||
$preset->mix($value); | ||
continue; | ||
} | ||
} | ||
$this->set($key, $value); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set($key, $value) | ||
{ | ||
$this->values[$key] = is_array($value) ? new self($value) : $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove($key) | ||
{ | ||
unset($this->values[$key]); | ||
} | ||
|
||
// <editor-fold desc="Magic Methods"> | ||
|
||
/** | ||
* @param array $data | ||
* @return static | ||
*/ | ||
public static function __set_state(array $data = array()) | ||
{ | ||
return new self($data); | ||
} | ||
|
||
// </editor-fold> | ||
} |
Oops, something went wrong.