PHP Configuration file parser
Library for parsing YAML, INI, JSON and PHP configuration files.



Config Component

Config component creates ConfigObject instances from config files. Currently supported formats: INI, JSON, PHP, YAML and custom drivers.

Install the component

The best way to install the component is using Composer.

composer require webiny/config

For additional versions of the package, visit the Packagist page.

Usage

To use Config component you will need a config file.

Example INI:

[properties]
a = "value"
b.name = "name"
b.value = "value"

Here is an example of creating a ConfigObject:

    $config = \Webiny\Components\Config\Config::getInstance()->ini('path/to/file.ini');

This will result in $config object containing the following properties:

    $config->properties->a = 'value';
    $config->properties->b->name = 'name';
    $config->properties->b->value = 'value';

Config is using internal caching system, so if you call this twice, you will get the cached value, including any config changes you made through the code. If, however, you need an original config from file, you need to specify the second parameter, $flushCache. This will reload the file and overwrite the existing cache:

    $config = \Webiny\Components\Config\Config::getInstance()->ini('path/to/file.ini', true);

If you don't want to use INI sections, or set custom nest delimiter, specify the following arguments:

    $config = \Webiny\Components\Config\Config::getInstance()->ini('path/to/file.ini', false, false, '_');

You can get your config as string in any format using the following methods:

    $string = $config->getAsJson();
    $string = $config->getAsPhp();
    $string = $config->getAsIni($useSections = true, $nestDelimiter = '.');
    $string = $config->getAsYaml($indent = 4);

And you can also use custom driver

    $driverInstance = new MyCustomDriver();
    $string = $config->getAs($driverInstance);

You can also merge one config with another ConfigObject or array:

// Simple merge
$config->mergeWith($config2);

// Or merge with multiple ConfigObjects and config arrays at once
$config->mergeWith([$config2, ['group2' => ['custom' => 'data']], $config3]);

Resources

To run unit tests, you need to use the following command:

$ cd path/to/Webiny/Component/Config/
$ composer.phar install
$ phpunit

To learn what you can do with Webiny Framework, checkout Webiny Platform - open-source content management system.

Explore Webiny Framework components:

  • Amazon currently supports implementation of Amazon S3
  • Annotations component for parsing annotations from a class, method or a property
  • Cache provides several caching libraries like Apc, Couchbase, Memcache and Redis
  • ClassLoader a PSR-0, PSR-4 and PEAR class loader
  • Config a very handy library for parsing YAML, INI, JSON and PHP configuration files
  • Crypt library for encoding, decoding and validating hashes
  • Entity an ODM layer (currently only supports MongoDB)
  • EventManager want to do event-based development, this is a library for you
  • Http library for parsing HTTP requests and creating HTTP responses
  • Image library for image manipulation
  • Logger PSR-3 log components for logging code execution in runtime
  • Mailer component for sending emails
  • Mongo MongoDB class wrapper
  • OAuth2 library for working with OAuth2, currently supports Facebook, LinkedIn and Google+
  • REST fully featured REST library with caching, security and rate control
  • Router handles defining, parsing, creating and matching url routes
  • Security provides authorization and authentication layer
  • ServiceManager want to write truly service based, loosely-coupled code, this library provides that
  • StdLib this component provides object wrappers for Arrays, Strings, Urls and DateTime data types
  • Storage storage abstraction layer that simplifies the way you work with files and directories
  • TemplateEngine provides a layer for rendering view templates and defining template plugins and manipulators
  • TwitterOAuth library for working with Twitter API using Twitter OAuth

SIGN UP FOR EARLY BETA ACCESS:

Lastest from our blog:

The Power of the Community

In the focus of recent feedback that I got, I think there is a need for me to justify some of the decisions we made while developing Webiny Framework.

Share & subscribe: