-
Notifications
You must be signed in to change notification settings - Fork 0
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 17b8d81
Showing
12 changed files
with
502 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,4 @@ | ||
vendor | ||
|
||
composer.lock | ||
.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,4 @@ | ||
checks: | ||
php: | ||
code_rating: true | ||
duplication: 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,32 @@ | ||
after_success: | ||
- travis_retry php vendor/bin/coveralls -x build/logs/coverage.xml | ||
- travis_retry php vendor/bin/test-reporter --coverage-report=build/logs/coverage.xml | ||
|
||
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: | ||
- mkdir -p build/logs | ||
- 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,59 @@ | ||
# vaibhavpandeyvpz/kunfig | ||
Helper library to easily merge & use multiple configuration files. | ||
|
||
[![Latest Version](https://img.shields.io/github/release/vaibhavpandeyvpz/kunfig.svg?style=flat-square)](https://github.com/vaibhavpandeyvpz/kunfig/releases) [![Build Status](https://img.shields.io/travis/vaibhavpandeyvpz/kunfig/master.svg?style=flat-square)](https://travis-ci.org/vaibhavpandeyvpz/kunfig) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/6fc5091b-eb1a-41b1-85ec-fd741badf360/mini.png)](https://insight.sensiolabs.com/projects/6fc5091b-eb1a-41b1-85ec-fd741badf360) [![](https://codeclimate.com/github/vaibhavpandeyvpz/kunfig/badges/gpa.svg)](https://codeclimate.com/github/vaibhavpandeyvpz/kunfig/badges) [![](https://codeclimate.com/github/vaibhavpandeyvpz/kunfig/badges/coverage.svg)](https://codeclimate.com/github/vaibhavpandeyvpz/kunfig/badges) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/vaibhavpandeyvpz/kunfig/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vaibhavpandeyvpz/kunfig/?branch=master) [![Coverage Status](https://coveralls.io/repos/github/vaibhavpandeyvpz/kunfig/badge.svg?branch=master)](https://coveralls.io/github/vaibhavpandeyvpz/kunfig?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/vaibhavpandeyvpz/kunfig.svg?style=flat-square)](https://packagist.org/packages/vaibhavpandeyvpz/kunfig) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) | ||
|
||
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](https://github.com/vaibhavpandeyvpz/kunfig/blob/master/LICENSE.md) file. |
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 @@ | ||
{ | ||
"autoload": { | ||
"psr-4": { | ||
"Kunfig\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Kunfig\\Tests\\": "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": { | ||
"codeclimate/php-test-reporter": "^0.3", | ||
"phpunit/phpunit": "^4.8", | ||
"satooshi/php-coveralls": "^0.7 || 1.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="build/logs/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,175 @@ | ||
<?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 implements ConfigInterface | ||
{ | ||
/** | ||
* @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 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 set($key, $value) | ||
{ | ||
$this->values[$key] = is_array($value) ? new self($value) : $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function remove($key) | ||
{ | ||
unset($this->values[$key]); | ||
} | ||
|
||
/** | ||
* {@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); | ||
} | ||
} | ||
|
||
// <editor-fold desc="Magic Methods"> | ||
|
||
/** | ||
* @param string $name | ||
* @return mixed | ||
*/ | ||
public function __get($name) | ||
{ | ||
return $this->get($name); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $value | ||
*/ | ||
public function __set($name, $value) | ||
{ | ||
$this->set($name, $value); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @return self | ||
*/ | ||
public function __set_state(array $data = array()) | ||
{ | ||
return new self($data); | ||
} | ||
|
||
// </editor-fold> | ||
|
||
// <editor-fold desc="\ArrayAccess"> | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
return $this->has($offset); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
return $this->get($offset); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetSet($offset, $value) | ||
{ | ||
$this->set($offset, $value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetUnset($offset) | ||
{ | ||
$this->remove($offset); | ||
} | ||
|
||
// </editor-fold> | ||
|
||
// <editor-fold desc="\Countable"> | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function count() | ||
{ | ||
return count($this->values); | ||
} | ||
|
||
// </editor-fold> | ||
|
||
// <editor-fold desc="\IteratorAggregate"> | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new \ArrayIterator($this->values); | ||
} | ||
|
||
// </editor-fold> | ||
} |
Oops, something went wrong.