<?php

use Illuminate\Config\Repository;
use Symfony\Component\Finder\Finder;

function bootstrapConfigRepo()
{
    $path = __DIR__ . '/tests/config/';

    $configs = Finder::create()->files()->name('*.php')->in($path)->depth(0);

    $repo = new Repository();

    /** @var  $file SplFileInfo */
    foreach($configs as $file)
    {
        $key = str_replace('.php', '', basename($file->getFilename()));
        $value = require($file->getPath() .'/'. $file->getFilename());

        $repo->set(sprintf("saml.%s", $key), $value);
    }

    return $repo;
}

if(!function_exists('config'))
{
    function config($key = null, $default = null)
    {
        $repo = bootstrapConfigRepo();

        if (is_null($key)) {
            return $repo;
        }

        if (is_array($key)) {
            return $repo->set($key);
        }

        return $repo->get($key, $default);
    }
}