PHPackages                             miladrahimi/phpconfig - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. miladrahimi/phpconfig

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

miladrahimi/phpconfig
=====================

A PHP configuration tool

v2.0(7y ago)93891MITPHPPHP &gt;=7.0

Since Jul 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/miladrahimi/phpconfig)[ Packagist](https://packagist.org/packages/miladrahimi/phpconfig)[ Docs](https://github.com/miladrahimi/phpconfig)[ RSS](/packages/miladrahimi-phpconfig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/c0ab7e6762a4e101595795366327bb5031e6f6805d962d18f787e6772af5c5ce/68747470733a2f2f7472617669732d63692e636f6d2f6d696c6164726168696d692f706870636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/miladrahimi/phpconfig)

PhpConfig
=========

[](#phpconfig)

A PHP configuration tool

Overview
--------

[](#overview)

PhpConfig is a minimal package for adding configuration tool to your PHP project. It provides different types of config repositries such as runtime array, php file, directory of php files, json file and directory of json files.

Installation
------------

[](#installation)

Run following command in the root directory of your project:

```
composer require miladrahimi/phpconfig
```

Getting started
---------------

[](#getting-started)

First of all, you need to provide configuration data to PhpConfig. It supports different types of repositories like php file, json file, and you can use anyone you are interested in.

As an example we use array repository as the configuration data source. The following example demonstrates how to use an array of data as the data source, how to access data in your code and also how to go deeper using `.` operator.

```
use MiladRahimi\PhpConfig\Config;
use MiladRahimi\PhpConfig\Repositories\ArrayRepository;

$data = [
    'name' => 'MyProject',
    'mysql' => [
        'hostname' => '127.0.0.1',
        'username' => 'root',
        'password' => 'secret',
        'database' => 'my_database'
    ]
];

$repository = new ArrayRepository($data);
$config = new Config($repository);

$name = $config->get('name'); // "MyProject"
$mysql_username = $config->get('mysql.username', 'root'); // "root"
$mysql_password => $config->get('mysql.password', ''); // "secret"
$locale = $config->get('locale', 'en'); // "en" (Default)

// Runtime config setting/manipulating
$config->set('locale', 'fa');

$locale = $config->get('locale', 'en'); // "fa"
```

Repositories
------------

[](#repositories)

The example above illustrates how to use a defined array as the respository for PhpConfig. In this section, we introduce some other repositories.

### Config PHP File

[](#config-php-file)

You can put the data array into a separate PHP file this way:

```
