yetanother/config

Yet another php configuration tool

dev-master 2013-08-04 21:04 UTC

This package is not auto-updated.

Last update: 2025-05-06 07:50:11 UTC


README

YetAnother Config — простой менеджер конфигурационных файлов.

Установка

Рекомендуемая установка через composer:

{
    "require": {
        "yetanother/config": "dev-master"
    }
}

Одиночный конфигурационный файл

// path/to/config.php

return array(
    'parameter1' => 'value1',
    'parameter2' => 'value2'
);
use YetAnother\Config\Config;

$config = new Config('path/to/config.php');
echo $config['parameter1']; // value1

Директория с конфигурационными файлами

config
┕database.php
┕routing.php
┕security.php
use YetAnother\Config\Config;

$config = new Config('path/to/config');
echo $config['database']['host'];

Использование переменных вместо массива

// path/to/config.php

$parameter1 = 'value1';
$parameter2 = 'value2';
use YetAnother\Config\Config;

$config = new Config('path/to/config.php');
echo $config['parameter1'];

Включение других конфигурационных файлов

config
┕config.php
┕database.php
┕routing.php
┕security.php
// config.php

$database = include(__DIR__.'/database.php');
$routing = include(__DIR__.'/routing.php');
$security = include(__DIR__.'/security.php');
// или
$database = $this->import('database');
$routing = $this->import('routing');
$security = $this->import('security');
// или
$database = $this->import(__DIR__.'/database.php');
$routing = $this->import(__DIR__.'/routing.php');
$security = $this->import(__DIR__.'/security.php');
use YetAnother\Config\Config;

$config = new Config('config/config.php');
echo $config['database']['host'];