Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dealnews/get-config
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: dealnews/get-config
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 7 commits
  • 4 files changed
  • 1 contributor

Commits on Nov 20, 2023

  1. Copy the full SHA
    ca0fe63 View commit details
  2. set version on phan action

    brianlmoon committed Nov 20, 2023
    Copy the full SHA
    a8bfe67 View commit details
  3. need yaml extension

    brianlmoon committed Nov 20, 2023
    Copy the full SHA
    1eebf91 View commit details
  4. Merge pull request #1 from dealnews/actions

    add github actions for testing
    brianlmoon authored Nov 20, 2023
    Copy the full SHA
    03cac8b View commit details

Commits on Sep 4, 2024

  1. Add support for an optional prefix

    brianlmoon committed Sep 4, 2024
    Copy the full SHA
    843ad2a View commit details
  2. add 8.3 testing

    brianlmoon committed Sep 4, 2024
    Copy the full SHA
    5de2966 View commit details
  3. Merge pull request #2 from dealnews/next

    Add support for an optional prefix
    brianlmoon authored Sep 4, 2024
    Copy the full SHA
    8f565de View commit details
Showing with 69 additions and 0 deletions.
  1. +35 −0 .github/workflows/ci.yml
  2. +6 −0 src/GetConfig.php
  3. +25 −0 tests/GetConfigTest.php
  4. +3 −0 tests/etc/prefix.ini
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Testing DealNews\GetConfig

on: [push]

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
include:
- operating-system: 'ubuntu-latest'
php-versions: '8.0'
phpunit-versions: 9
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Composer Install
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-versions }}

- name: PHPUnit tests
uses: php-actions/phpunit@v3
with:
php_extensions: "pcov yaml"
version: "9.6"
php_version: ${{ matrix.php-versions }}

- name: Run Phan
uses: k1LoW/phan-action@v0
6 changes: 6 additions & 0 deletions src/GetConfig.php
Original file line number Diff line number Diff line change
@@ -199,6 +199,12 @@ public function get(string $var): ?string {
if (!array_key_exists($var, $this->config)) {
$value = null;

$prefix = getenv('GET_CONFIG_PREFIX');

if (!empty($prefix) && strpos($var, $prefix . '.') === false) {
$var = $prefix . '.' . $var;
}

$check_vars = [
str_replace('.', '_', strtoupper($var)),
str_replace('.', '_', strtolower($var)),
25 changes: 25 additions & 0 deletions tests/GetConfigTest.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,31 @@
use \DealNews\GetConfig\GetConfig;

class GetConfigTest extends \PHPUnit\Framework\TestCase {

public function testPrefix() {
$config = new GetConfig(__DIR__ . '/etc/prefix.ini', __DIR__ . '/etc/config.d/');

putenv('GET_CONFIG_PREFIX=prefix');
putenv('PREFIX_FOO_TEST=BAZ');

$this->assertEquals(
'bar',
$config->get('test.foo')
);

$this->assertEquals(
'1',
$config->get('prefix.test.bar')
);

$this->assertEquals(
'BAZ',
$config->get('foo.test')
);

putenv('GET_CONFIG_PREFIX=');
}

public function testFindFile() {
$config = new GetConfig(__DIR__ . '/etc/config.ini', __DIR__ . '/etc/config.d/');

3 changes: 3 additions & 0 deletions tests/etc/prefix.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[prefix]
prefix.test.foo = bar
prefix.test.bar = 1