PHPackages                             nikoutel/helionconfig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. nikoutel/helionconfig

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

nikoutel/helionconfig
=====================

A versatile configuration parser. Can handle multiple configuration formats.

v2.0(6y ago)56752[2 issues](https://github.com/nikoutel/HelionConfig/issues)[1 PRs](https://github.com/nikoutel/HelionConfig/pulls)1MPL-2.0PHP

Since Jul 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nikoutel/HelionConfig)[ Packagist](https://packagist.org/packages/nikoutel/helionconfig)[ RSS](/packages/nikoutel-helionconfig/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (4)Used By (1)

HelionConfig
============

[](#helionconfig)

**A versatile configuration parser. Can handle multiple configuration formats.**

*HelionConfig* is a tool for reading (and soon, writing) different configuration types (INI, XML, JSON, apache, PHP arrays, generic conf), returning the whole configuration, a section, or a specific value.

Usage
-----

[](#usage)

```
$helionConfig = new HelionConfig();
$configReader = $helionConfig->getConfigReader(ConfigType::XML, $options);
$configSrc = 'file.xml';
$config = $configReader->getConfig($configSrc);
```

```
$value = $configReader->getConfigValue($key, $config);
```

```
$configAsArray = $config->asArray();
$configAsArrayFlat = $config->asArrayFlat();
```

### Parameters

[](#parameters)

***ConfigType***

A `ConfigType` parameter.

Available types are:

- `ConfigType::INI`
- `ConfigType::XML`
- `ConfigType::JSON`
- `ConfigType::PHPARRAY` *(configuration stored in a php array)* \*
- `ConfigType::APACHE` *(`apache2.conf` / `httpd.conf` type configuration)*
- `ConfigType::CONF` *(configurable generic configuration type, see options and examples)*

\* The PHPArray file should only include an array with the configuration data, and a `return` statement returning the array.

Method `$helionConfig->listConfigTypes()` returns all available config types.

***configSrc***

The configuration source could be a file path, URL, or a configuration string.

***options*** *(optional)*

An options array can be passed to the `getConfigReader` method of `HelionConfig`.

Array elements:

- `rootName`: name of the root object element - *Default: `configRoot`*
- `sectionSeparator`: symbol used to denote the separation of subsections and value - *Default: `.`*
- `libxmlOptions`: used to specify optional *libxml* parameters - *e.g.:* `LIBXML_PARSEHUGE, LIBXML_NOBLANKS`
- `jsonOptions`: used to specify optional *json* constants - *e.g.:* `JSON_PRETTY_PRINT, JSON_NUMERIC_CHECK`
- `curlOptions`: an array specifying additional *curlopt* constants - *e.g.:*
    - `CURLOPT_HTTPAUTH => CURLAUTH_BASIC,`
    - `CURLOPT_USERPWD => 'AzureDiamond:hunter2'`
- `genericConf`: used to specify the symbols for the configurable generic configuration format - *Default:*
    - `'sectionStart' => "["`
    - `'sectionEnd' => "]"`
    - `'equals' => "="`
    - `'multiLineSeparator' => "\\"`
    - `'commentStart' => ";"`

*Options Example:*

```
$options = array(
    'sectionSeparator' => ':',
    'rootName' => 'myConf',
    'libxmlOptions' => array(
        LIBXML_PARSEHUGE, LIBXML_NOBLANKS
    ),
    'jsonOptions' => array(
        JSON_PRETTY_PRINT, JSON_NUMERIC_CHECK
    ),
    'curlOptions' => array(
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
        CURLOPT_USERPWD => 'AzureDiamond:hunter2'
    ),
    'genericConf' => array(
        'sectionStart' => "[",
        'sectionEnd' => "]",
        'equals' => "=",
        'multiLineSeparator' => "\\",
        'commentStart' => "#",
    )
);
```

### Return values

[](#return-values)

*HelionConfig* returns a `HelionConfigValue` Object representing configuration data. All data are enclosed in a root object element named `configRoot` (can be changed through the options array).

Each directive and each section, is represented by an `HelionConfigValue` Object, and multiple subsections and values, are grouped in arrays of `HelionConfigValue` Objects.

Specific values or subsections can be returned with the `getConfigValue()` method, of the `HelionConfigValue` Object. Nested sections can be accessed by chaining the subsections with the `sectionSeparator` options array element (default is `.`) (*e.g.:* `section1.section2.key`)

To convert a `HelionConfigValue` Object to an array, the method `asArray()` is provided. Additionally the method `asArrayFlat()` returns a flat Array. Sections and value are separated with `sectionSeparator`.

Requirements
------------

[](#requirements)

- PHP 7 (min)
- SimpleXML php extension
- libxml php extension
- JavaScript Object Notation php extension (json)
- Client URL Library Object Notation php extension (curl)

Install
-------

[](#install)

**composer:**

```
composer require nikoutel/helionconfig

```

Examples
--------

[](#examples)

```
require '/../vendor/autoload.php';
use Nikoutel\HelionConfig\HelionConfig;
use Nikoutel\HelionConfig\ConfigType\ConfigType;
```

**Example #1** (simple .ini file):

```
; db.ini
[owner]
name=John Doe
organization=Acme Widgets Inc.

[database]
server=192.0.2.62
port=143
```

```
$configSrc = 'db.ini';

$helionConfig = new HelionConfig();
$configReader = $helionConfig->getConfigReader(ConfigType::INI, $options);
$config = $configReader->getConfig($configSrc);

$port = $configReader->getConfigValue('database.port', $config);
```

*will output:*

```
$config:
Nikoutel\HelionConfig\HelionConfigValue Object
(
    [helionConfigName] => configRoot
    [helionConfigValue] => Array
        (
            [owner] => Nikoutel\HelionConfig\HelionConfigValue Object
                (
                    [helionConfigName] => owner
                    [helionConfigValue] => Array
                        (
                            [name] => Nikoutel\HelionConfig\HelionConfigValue Object
                                (
                                    [helionConfigName] => name
                                    [helionConfigValue] => John Doe
                                    [helionConfigAttributes] =>
                                )
                            [organization] => Nikoutel\HelionConfig\HelionConfigValue Object
                                (
                                    [helionConfigName] => organization
                                    [helionConfigValue] => Acme Widgets Inc.
                                    [helionConfigAttributes] =>
                                )
                        )
                    [helionConfigAttributes] =>
                )
            [database] => Nikoutel\HelionConfig\HelionConfigValue Object
                (
                    [helionConfigName] => database
                    [helionConfigValue] => Array
                        (
                            [server] => Nikoutel\HelionConfig\HelionConfigValue Object
                                (
                                    [helionConfigName] => server
                                    [helionConfigValue] => 192.0.2.62
                                    [helionConfigAttributes] =>
                                )
                            [port] => Nikoutel\HelionConfig\HelionConfigValue Object
                                (
                                    [helionConfigName] => port
                                    [helionConfigValue] => 143
                                    [helionConfigAttributes] =>
                                )
                        )
                    [helionConfigAttributes] =>
                )
        )
    [helionConfigAttributes] =>
)

```

and:

```
$port = $configReader->getConfigValue('database.port', $config);
```

*will output:*

```
$port: 143

```

**Example #2** (config-like json passed as a string):

```
$configSrc = '{ "isbn": "0-13-110362-8",
                "author": [
                     {"firstname": "Brian", "lastname": "Kernighan"},
                     {"firstname": "Dennies", "lastname": "Ritchie"}],
                 "title": "The C Programming Language",
                 "category": ["Programming", "Technology"]}';

$helionConfig = new HelionConfig();
$configReader = $helionConfig->getConfigReader(ConfigType::JSON, $options);

$array = $configReader->getConfig($configSrc)->asArrayFlat();
```

*will output:*

```
Array
(
    [isbn] => 0-13-110362-8
    [author.0.firstname] => Brian
    [author.0.lastname] => Kernighan
    [author.1.firstname] => Dennies
    [author.1.lastname] => Ritchie
    [title] => The C Programming Language
    [category.0] => Programming
    [category.1] => Technology
)

```

**Example #3** (configurable generic configuration type):

```
# /etc/mysql/my.cnf
[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
# * Basic Settings
user		= mysql
port		= 3306

```

MySQL uses INI type configuration files but with comments marked with the non-standard *‘#’*

```
$options = array(
    'genericConf' => array(
        'commentStart' => "#",
    )
);

$helionConfig = new HelionConfig();
$configReader = $helionConfig->getConfigReader(ConfigType::CONF, $options);
$config = $configReader->getConfig('/etc/mysql/my.cnf');

// get only the 'mysqld' section
$mysqldCofigSection = $configReader->getConfigValue('mysqld', $config);
```

*will output:*

```
$mysqldCofigSection:
Nikoutel\HelionConfig\HelionConfigValue Object
(
    [helionConfigName] => mysqld
    [helionConfigValue] => Array
        (
            [user] => Nikoutel\HelionConfig\HelionConfigValue Object
                (
                    [helionConfigName] => user
                    [helionConfigValue] => mysql
                    [helionConfigAttributes] =>
                )
            [port] => Nikoutel\HelionConfig\HelionConfigValue Object
                (
                    [helionConfigName] => port
                    [helionConfigValue] => 3306
                    [helionConfigAttributes] =>
                )
        )
    [helionConfigAttributes] =>
)

```

and:

```
// get the 'port' from the 'mysqld' section
$port = $configReader->getConfigValue('port', $mysqldCofigSection);
```

*will output:*

```
$port: 3306

```

**Example #4** (apache vhost conf):

```

    DocumentRoot /var/www/api
    ServerName api.example.com

        AllowOverride All
        Require all granted

```

```
$helionConfig = new HelionConfig();
$configReader = $helionConfig->getConfigReader(ConfigType::APACHE);
$config = $configReader->getConfig($configSrc);

$array = $config->asArray();
$arrayFlat = $config->asArrayFlat()
```

*will output:*

```
$array:
Array
(
    [helionConfigName] => configRoot
    [helionConfigValue] => Array
        (
            [VirtualHost] => Array
                (
                    [helionConfigName] => VirtualHost
                    [helionConfigValue] => Array
                        (
                            [DocumentRoot] => Array
                                (
                                    [helionConfigName] => DocumentRoot
                                    [helionConfigValue] => /var/www/api
                                )

                            [ServerName] => Array
                                (
                                    [helionConfigName] => ServerName
                                    [helionConfigValue] => api.example.com
                                )

                            [Directory] => Array
                                (
                                    [helionConfigName] => Directory
                                    [helionConfigValue] => Array
                                        (
                                            [AllowOverride] => Array
                                                (
                                                    [helionConfigName] => AllowOverride
                                                    [helionConfigValue] => All
                                                )
                                            [Require] => Array
                                                (
                                                    [helionConfigName] => Require
                                                    [helionConfigValue] => all granted
                                                )
                                        )
                                    [helionConfigAttributes] => /var/www/api
                                )
                        )
                    [helionConfigAttributes] => *:80
                )
        )
)

$arrayFlat:
Array
(
    [VirtualHost.DocumentRoot] => /var/www/api
    [VirtualHost.ServerName] => api.example.com
    [VirtualHost.Directory.AllowOverride] => All
    [VirtualHost.Directory.Require] => all granted
    [VirtualHost.Directory.@attribute] => /var/www/api
    [VirtualHost.@attribute] => *:80
)

```

Todo
----

[](#todo)

- YAML
- TOML
- Add writing/editing capabilities (getConfigWriter())
- Combine sources

License
-------

[](#license)

This software is licensed under the [MPL](http://www.mozilla.org/MPL/2.0/) 2.0:

```
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

2

Last Release

2545d ago

Major Versions

v1.0 → v2.02019-07-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/26b8ff0aae33318299950ec6d4e7808d97b7483ea1969f8f50155fa6fcb77583?d=identicon)[nikoutel](/maintainers/nikoutel)

---

Top Contributors

[![nikoutel](https://avatars.githubusercontent.com/u/3975133?v=4)](https://github.com/nikoutel "nikoutel (72 commits)")

---

Tags

apacheconfigurationinijsonparserphp-arrayxmljsonconfigurationxmlparserapacheiniphp arrays

### Embed Badge

![Health badge](/badges/nikoutel-helionconfig/health.svg)

```
[![Health](https://phpackages.com/badges/nikoutel-helionconfig/health.svg)](https://phpackages.com/packages/nikoutel-helionconfig)
```

###  Alternatives

[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

1.0k13.8M187](/packages/hassankhan-config)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.3k1](/packages/m1-vars)[thewunder/conphigure

Framework Agnostic Configuration Library

3120.6k](/packages/thewunder-conphigure)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
