Download the PHP package radiergummi/libconfig without Composer

On this page you can find all versions of the php package radiergummi/libconfig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package libconfig

libconfig Build Status volkswagen status Documentation Join the chat at https://gitter.im/Radiergummi/libconfig

Simple php class to create a key-value storage. Basically, you can just throw your configuration at it, be it arrays, json, files or even directories, and libconfig will make it accessible in an intuitive way. You can get, set and add it, count it, iterate over it or access it as an array. Each method has its tricks up its sleeve. More on that below.
 

Note: I also made a singleton version of this which is available here.
Why? Because using stuff like Config::get('key') from anywhere without an instance is pretty darn comfortable.

Installation

Installation via Composer (Packagist):

  1. Include the following in your composer.json file:

    "require": {
        ...
        "radiergummi\libconfig": "~1.0"
    }
  2. Then, run php composer.phar install

Installation via source:

  1. Download from Github
  2. Drop the src/libconfig folder into your codebase at vendor/Radiergummi (you don't need the parent folders)
  3. Use a PSR-4 Autoloader to include it!

Usage

Creating a Config object

Create a config object like this:

where $data can be an array or a json string, a file or folder path.
 

Creating a Config object with a file as a parameter

To directly include a json file, use

The only requirement is the complete path to be valid.  

I often use php files like the one below to store configuration. So you could also use

PHP Config file:

 

Creating a Config object with a folder as a parameter

To parse a folder containing your configuration files, use

The only requirement is the complete path to be valid.  

A note on INI files: Honestly, why would you want to use those for configuration when you have php and json at hand? Maybe when I get a good idea on how to implement that in an elegant way.  
 

Advice on implementation

Incorporate this into your project: Set the namespace to that of your app and keep it in the app system directory. That way, you can access the config the most hassle-free way.
Catch possible exceptions: Libconfig will throw a RuntimeException immediately if data cannot be read. If you know something could go wrong, set up try-catch blocks.
Don't hardcode: Use config files whenever possible - for files, routes, i18n, paths and classlists, ... .
Be reasonable: There comes a point where redis or a real DB might make more sense. Reevaluate from time to time.
Hack the code however you like: You are free to use this library in any project, commercial or not (see the license). However, it would be nice of you to drop a curious fella a note what you used my work for and what you changed :).  
 

Methods

set

inserts a value into a key:

That will add the following to the config array:

To set nested config values, you can use dots to seperate keys:

That will add the following to the config array:

 
 

get

returns the value for a given key:

To access nested config values, you can use dots to seperate keys:

You can optionally specify a fallback value in case the desired key is not present:

To retrieve the whole configuration, just call get without arguments:

 
 

has

checks wether a setting exists or not

 
 

erase

removes a key from the settings

 
 

add

Adds another array to the configuration. The data is merged, which means that keys with the same name will overwrite previously existing ones. Maybe a possibility to insert them with changed names should be implemented here?

 
 

Magic methods

__tostring

returns the complete data array:

(Note: This is redundant. You can either call $config->get() or just $config, same effect. I find it to be not very self-documenting, but who am I to tell you how to code.)

 
 

Implemented Interfaces

Array access

You can also access and edit all data as an array:

 
 

Countable

The Config object can be counted:

 
 

Iterator

You are able to iterate over the Config object:

 
 

Some thoughts on Exceptions

I have only implemented RuntimeException as the exception type throughout libconfig. Why? Possible things that can go wrong are files not being found or data not being parsable. In either case, you've got a problem you should catch:

That way, exception handling is bound to your app and you don't have a few more arbitrary exception types to deal with.

 
 

TODO

Bugs

Improvements

Features

 
 

How to contribute

I would love to see other people contribute their ideas to this project. However to ease the process, please keep the following in mind:

Thank you!


All versions of libconfig with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package radiergummi/libconfig contains the following files

Loading the files please wait ....