Skip to content

Commit b83af84

Browse files
committed
updated
1 parent 1e7a46d commit b83af84

13 files changed

+273
-1
lines changed

.codeclimate.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
engines:
3+
duplication:
4+
enabled: true
5+
config:
6+
languages:
7+
- javascript
8+
- php
9+
eslint:
10+
enabled: true
11+
fixme:
12+
enabled: true
13+
phpmd:
14+
enabled: true
15+
checks:
16+
Naming/ShortVariable:
17+
enabled: false
18+
CleanCode/ElseExpression:
19+
enabled: false
20+
CleanCode/BooleanArgumentFlag:
21+
enabled: false
22+
CleanCode/StaticAccess:
23+
enabled: false
24+
ratings:
25+
paths:
26+
- "**.js"
27+
- "**.php"
28+
exclude_paths:
29+
- tests/
30+
- build/

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# More info at http://editorconfig.org
2+
3+
# top-most editorconfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
charset = utf-8
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
indent_size = 2
16+
trim_trailing_whitespace = false

.gitattributes

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/.codeclimate.yml export-ignore
11+
/.editorconfig export-ignore
12+
/tests export-ignore
13+
/build export-ignore
14+
.gitkeep export-ignore
15+
.phpunit.result.cache export-ignore

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# git stuff
2+
.git
3+
4+
# composer files
5+
composer.phar
6+
composer.lock
7+
vendor
8+
9+
# phpunit files
10+
phpunit.phar
11+
.phpunit.result.cache

.scrutinizer.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
code_rating: true
7+
remove_extra_empty_lines: true
8+
remove_php_closing_tag: true
9+
remove_trailing_whitespace: true
10+
fix_use_statements:
11+
remove_unused: true
12+
preserve_multiple: false
13+
preserve_blanklines: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: php
2+
3+
php:
4+
- 7.2
5+
6+
before_script:
7+
- composer self-update
8+
- composer update nothing
9+
- composer --prefer-source --dev install

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# config
2-
Configuration package for Phoole
2+
[![Build Status](https://travis-ci.com/phoole/config.svg?branch=master)](https://travis-ci.com/phoole/config)
3+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phoole/config/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phoole/config/?branch=master)
4+
[![Code Climate](https://codeclimate.com/github/phoole/config/badges/gpa.svg)](https://codeclimate.com/github/phoole/config)
5+
[![PHP 7](https://img.shields.io/packagist/php-v/phoole/config)](https://packagist.org/packages/phoole/config)
6+
[![Latest Stable Version](https://img.shields.io/github/v/release/phoole/config)](https://packagist.org/packages/phoole/config)
7+
[![License](https://img.shields.io/github/license/phoole/config)]()
8+
9+
A slim and fast configuration loader lib using PHP, JSON, YAML files

composer.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "phoole/config",
3+
"type": "library",
4+
"license": "Apache-2.0",
5+
"version": "1.0.0",
6+
"description": "Config library for Phoole",
7+
"keywords": ["phoole", "library", "php", "config"],
8+
"authors": [
9+
{
10+
"name": "Hong Zhang",
11+
"homepage": "https://github.com/phoole"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.2.0",
16+
"phoole/base": "~1.0.6"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^8"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Phoole\\Config\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Phoole\\Tests\\": "tests/"
29+
}
30+
},
31+
"scripts": {
32+
"test": "phpunit",
33+
"check": "phpcs --standard=psr12 src/",
34+
"format": "phpcbf --standard=psr12 src/"
35+
}
36+
}

phpunit.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
bootstrap="vendor/autoload.php"
11+
>
12+
<testsuites>
13+
<testsuite name="test suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

src/Config.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* Phoole (PHP7.2+)
5+
*
6+
* @category Library
7+
* @package Phoole\Config
8+
* @copyright Copyright (c) 2019 Hong Zhang
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Phoole\Config;
13+
14+
/**
15+
* Config
16+
*
17+
* @package Phoole\Config
18+
*/
19+
class Config implements ConfigInterface
20+
{
21+
}

src/ConfigInterface.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* Phoole (PHP7.2+)
5+
*
6+
* @category Library
7+
* @package Phoole\Config
8+
* @copyright Copyright (c) 2019 Hong Zhang
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Phoole\Config;
13+
14+
/**
15+
* ConfigInterface
16+
*
17+
* @package Phoole\Config
18+
*/
19+
interface ConfigInterface
20+
{
21+
/**
22+
* Get a configure value. NUll return if not found
23+
*
24+
* If you want a default value,
25+
* ```php
26+
* $user = $conf->get('user) ?? 'dummy';
27+
* ```
28+
*
29+
* @param string $id
30+
* @return mixed
31+
*/
32+
public function get(string $id);
33+
34+
/**
35+
* Has a configure key
36+
*
37+
* @param string $id
38+
* @return bool
39+
*/
40+
public function has(string $id): bool;
41+
42+
/**
43+
* Config object is supposed to be IMMUTABLE once created.
44+
*
45+
* Set new value will return a new copy
46+
* ```php
47+
* $newconf = $conf->with('db.user', 'system');
48+
* ```
49+
*
50+
* @param string $id
51+
* @param mixed $value
52+
* @return ConfigInterface
53+
*/
54+
public function with(string $id, $value): ConfigInterface;
55+
}

src/Loader/LoaderInterface.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* Phoole (PHP7.2+)
5+
*
6+
* @category Library
7+
* @package Phoole\Config
8+
* @copyright Copyright (c) 2019 Hong Zhang
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Phoole\Config\Loader;
13+
14+
/**
15+
* LoaderInterface
16+
*
17+
* @package Phoole\Config
18+
*/
19+
interface LoaderInterface
20+
{
21+
/**
22+
* Load group(specific) config(s) base on environment value.
23+
*
24+
* - if $environment == '', use the default environment
25+
* - if $group == '', load all avaiable groups
26+
*
27+
* ```php
28+
* $this->load('db');
29+
* $this->load('db', 'production/host1');
30+
* ```
31+
*
32+
* @param string $group
33+
* @param string $environment
34+
* @return array
35+
*/
36+
public function load(string $group, string $environment = ''): array;
37+
}

tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)