PHP Classes

PHP Config for INI: Store and manipulation configuration in INI files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 180 All time: 8,719 This week: 206Up
Version License PHP version Categories
config-for-ini 1.0GNU General Publi...5.0PHP 5, Files and Folders, Configuration
Description 

Author

This class can store and manipulation configuration in INI files.

It can parse a given INI configuration file and store it as an nested associative array.

Configuration values may be changed by setting class variables with the names of the respective configuration keys.

The class can regenerate the configuration in the INI format and return it as a string or save it to a file.

Class to store and manipulate settings through the INI files.
With the class Config is load INI files, with or without sections, access and modify settings, display the contents of the settings and save them in the same INI file or in a new INI file.

Picture of Everton da Rosa
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

 

Example

<?php

/*
 * Copyright (C) 2014 Everton
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Este arquivo demonstra o uso da classe Config.
 *
 */
require 'config.class.php'; //inclui a classe

$conf = new Config('exemplo.ini');//crianto um objeto de configuração

echo $conf->conf0.PHP_EOL;//acessando uma configuração que não está dentro de uma seção

echo $conf->section1->conf1.PHP_EOL;//acessando configuração dentro de seção

echo $conf->conf0 = 'Esta configuração foi modificada';//alterando uma configuração
echo PHP_EOL;

require
'extend_config.example.php';;//incluindo uma extensão de Config

$xconf = new ConfigExample('exemplo.ini');//criando uma instância de ConfigExample

try{//definindo um valor inválido para conf0 para demonstrar a função de validação
   
echo $xconf->conf0 = 13131313;
    echo
PHP_EOL;
} catch (
Exception $ex) {
    echo
$ex->getMessage().PHP_EOL;
    echo
"O valor de conf0 continua {$xconf->conf0}".PHP_EOL;
}

echo
'Exibindo as configurações'.PHP_EOL;
$conf->show();//Exibe o conteúdo da configuração. Interessante para depuração.

//salva a configuração (com alterações num novo arquivo). Também pode ser usado para update no arquivo original
//Atente para o fato de que os comentários presentes no arquivo INI original não serão salvos.
$filename = 'exemplo_modificado.ini';
$save = $conf->save($filename);
echo
"A configuração foi salva em $filename ($save bites salvos)".PHP_EOL;


  Files folder image Files (35)  
File Role Description
Files folder imagedoc (13 files, 1 directory)
Files folder imagenbproject (2 files, 1 directory)
Plain text file config.class.php Class class file source
Accessible without login Plain text file exemplo.ini Data ini file for exemple
Accessible without login Plain text file exemplo_modificado.ini Data Auxiliary data
Plain text file extend_config.example.php Class Example extension class
Accessible without login Plain text file index.php Example file with example usage

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:180
This week:0
All time:8,719
This week:206Up