2017 © Pedro Peláez
 

library config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

image

aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  • Sunday, March 4, 2018
  • by aedart
  • Repository
  • 1 Watchers
  • 3 Stars
  • 442 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 3 % Grown

The README.md

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Deprecated- Config Loader

Package has been replaced by aedart/athenaeum, (*2)

A utility for loading various types of configuration files and parse them to a Laravel Configuration Repository. This package contains a set of default file-parsers, which can be applied. However, if you have a need for a different kind of parser, then you can "simply" create one, add it to the loader., (*3)

Contents

When to use this

  • When you need to load configuration from a file
  • (When you need to load configuration from multiple files)

How to install


composer require aedart/config-loader

This package uses composer. If you do not know what that is or how it works, I recommend that you read a little about, before attempting to use this package., (*4)

Quick start

Supported file types

File Extension Parser
*.ini \Aedart\Config\Loader\Parsers\Ini
*.json \Aedart\Config\Loader\Parsers\Json
*.php (php array) \Aedart\Config\Loader\Parsers\PHPArray
*.yml (also *.yaml) \Aedart\Config\Loader\Parsers\Yaml

Inside a Laravel project

Service Provider

The first thing you need to to, is to register the service provider;, (*5)

\Aedart\Config\Loader\Providers\ConfigurationLoaderServiceProvider::class

Load configuration

After you have specified the service provider, you can use the loader. In the following example, a directory path is provided and the files contained in that directory are loaded and parsed;, (*6)

use Aedart\Config\Loader\Loaders\ConfigLoader;

// Path to some directory that contains the configuration file(s)
$path = 'config/';

// Create a new loader instance
$loader = new ConfigLoader($path);

// Load and parse the configuration files
// NB: Is added directly to Laravel's configuration, can be accessed normally via the Config facade...
$loader->load();

// Obtain the configuration repository
$config = $loader->getConfig();

Outside a Laravel project

When working outside a Laravel project, you need to create a few more instances, which the loader is dependent upon;, (*7)

use Aedart\Config\Loader\Loaders\ConfigLoader;
use Aedart\Config\Loader\Factories\DefaultParserFactory;
use Illuminate\Config\Repository;
use Illuminate\Filesystem\Filesystem;

// Path to some directory that contains the configuration file(s)
$path = 'config/';

// Create a new loader instance
$loader = new ConfigLoader($path);

// Specify the required dependencies
$loader->setConfig(new Repository());
$loader->setFile(new Filesystem());
$loader->setParserFactory(new DefaultParserFactory());

// Load and parse the configuration files
$loader->load();

// Obtain the configuration repository
$config = $loader->getConfig();

Load and parse a single file

You can also load and parse a single file, instead of an entire directory;, (*8)


// Provided you have created an instance of the configuration loader, // simply specify the full path to the configuration file $config = $loader->parse('config/users.yml');

How to access the configuration

If you are not familiar with Laravel's configuration repository, please review its documentation., (*9)

Example PHP Array configuration file, (*10)

(config/users.php), (*11)

return [
    'message' => 'Hallo World'
];

Example of accessing the message, (*12)


// ... (loading and parsing not shown) ... // Fetch the message key $message = $config->get('users.message'); echo $message; // Outputs 'Hallo World'

Custom configuration file parser

If you need a custom parser, then you can create one by implementing the \Aedart\Config\Loader\Contracts\Parsers\Parser interface., (*13)

However, you also need to add your parser to a parser factory. Please review the \Aedart\Config\Loader\Contracts\Factories\ParserFactory interface, as well as the default factory provided in this package; \Aedart\Config\Loader\Factories\DefaultParserFactory, (*14)

Contribution

Have you found a defect ( bug or design flaw ), or do you wish improvements? In the following sections, you might find some useful information on how you can help this project. In any case, I thank you for taking the time to help me improve this project's deliverables and overall quality., (*15)

Bug Report

If you are convinced that you have found a bug, then at the very least you should create a new issue. In that given issue, you should as a minimum describe the following;, (*16)

  • Where is the defect located
  • A good, short and precise description of the defect (Why is it a defect)
  • How to replicate the defect
  • (A possible solution for how to resolve the defect)

When time permits it, I will review your issue and take action upon it., (*17)

Fork, code and send pull-request

A good and well written bug report can help me a lot. Nevertheless, if you can or wish to resolve the defect by yourself, here is how you can do so;, (*18)

  • Fork this project
  • Create a new local development branch for the given defect-fix
  • Write your code / changes
  • Create executable test-cases (prove that your changes are solid!)
  • Commit and push your changes to your fork-repository
  • Send a pull-request with your changes
  • Drink a Beer - you earned it :)

As soon as I receive the pull-request (_and have time for it_), I will review your changes and merge them into this project. If not, I will inform you why I choose not to., (*19)

Acknowledgement

Versioning

This package follows Semantic Versioning 2.0.0, (*20)

License

BSD-3-Clause, Read the LICENSE file included in this package, (*21)

The Versions

04/03 2018

dev-master

9999999-dev https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

04/03 2018

5.0.0

5.0.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

14/10 2017

4.0.0

4.0.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

31/01 2017

3.0.2

3.0.2.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

27/01 2017

3.0.1

3.0.1.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

27/01 2017

3.0.0

3.0.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

08/01 2017

2.1.0

2.1.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

27/08 2016

2.0.0

2.0.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

27/08 2016

1.1.1

1.1.1.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

03/01 2016

1.1.0

1.1.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

21/10 2015

1.0.1

1.0.1.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader

21/10 2015

1.0.0

1.0.0.0 https://github.com/aedart/config-loader

Utility for loading various types of configuration files and parse them to a Laravel Configuration Repository

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alin Eugen Deac

parser config loader