Download the PHP package elbucho/config without Composer

On this page you can find all versions of the php package elbucho/config. 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 config

elbucho/config

This project provides an object-oriented configuration system for all of your config files. This includes support for the following file types:

Usage

The Config class is instantiated with an array of key => value pairs. Nested keys are instantiated as separate Config classes.

Retrieving values

Keys can be accessed either through the magic __get() method, or via the get() method. The get() method supports dotted notation (see examples below).

$config = new Elbucho\Config\Config(array('foo' => array('bar' => 1)));

$config->foo->bar == 1

$config->get('foo.bar') == 1

$config->get('foo')->bar == 1

$config->get('foo')->get('bar') == 1

When using the magic __get() method, if a key does not exist, the Config class will return false. When using the get() method, you can specify the return value if the key does not exist.

$config->foo->bar1 == false

$config->get('foo.bar1', 2) == 2

$config->foo->get('bar1', 'missing') == 'missing'

Setting values

You can set values by using either the magic __set() method, or by using the set() method:

$config->foo->bar = 2

$config->set('foo.bar', 2)

$config->foo->set('bar', 2)

If you use the set() method, and specify a path that doesn't currently exist, that path will be created:

$config->get('foo.bar.foobar') == false

$config->set('foo.bar.foobar.asdf', 'fdsa')

Un-setting values

You can unset values either by using the magic __unset() method, or by using remove():

unset($config->foo->bar)

$config->remove('foo.bar')

$config->foo->remove('bar')

Finding whether a key exists

You can determine whether a key has been set via either the magic __isset() method, or with exists():

isset($config->foo->bar)

$config->exists('foo.bar')

$config->foo->exists('bar')

Returning as an array

You can return the Config object as an array by using the toArray() method:

$config->toArray() == ['foo' => ['bar' => 1]]

Appending values

If you wish to merge two Config classes, you can use the append function:

$config1->toArray() == ['foo' => ['bar' => 1, 'baz' => 2]]

File loaders

You can load a configuration file into a Config object via the use of one of the Loader classes:

File Type Loader Class
INI Elbucho\Config\Loader\File\IniFileLoader
JSON Elbucho\Config\Loader\File\JsonFileLoader
PHP Elbucho\Config\Loader\File\PhpFileLoader
XML Elbucho\Config\Loader\File\XmlFileLoader
YAML/YML Elbucho\Config\Loader\File\YamlFileLoader

To load a file and create a Config-compatible array from the values stored therein, do this:

Directory Loader

You can also load all of the files in a given directory with the directory loader:

File names (minus the extensions) will be listed as keys in the $config object. For example, let's assume this file exists in your config directory as "database.yml":

When you run the code above to import this file, here is how your config object will look:

Environment Overwriting

In many cases, you will want to have a set of config files that are applicable for all environments, and will want to overwrite specific keys with environment-specific values.

For example, let's say that we have a config folder format like this:

In this example, we want the keys that are common to all environments in /config/database.yml and /config/framework.yml loaded, but we want to overwrite certain ones with the values in /config/environment/live since we're in the live environment. Here's how you would do that:

Extending the class

Each loader must conform to the Elbucho\Config\LoaderInterface interface. If you would like to write a custom file loader, it should throw an Elbucho\Config\InvalidFileException exception when encountering issues opening or parsing the file.

New loaders can also be registered with the DirectoryLoader via the registerLoader() method:


All versions of config with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
doctrine/inflector Version ^1.0
pds/skeleton Version ^1.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 elbucho/config contains the following files

Loading the files please wait ....