PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (35)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 180 This week: 1All time: 8,714 This week: 571Up
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  
Name: Everton da Rosa <contact>
Classes: 17 packages by
Country: Brazil Brazil
Age: 42
All time rank: 78856 in Brazil Brazil
Week rank: 33 Up3 in Brazil Brazil Up
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  
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

  Files folder image Files  /  doc  
File Role Description
Files folder imageresources (11 files)
  Accessible without login HTML file 404.html Doc. Documentation
  Accessible without login HTML file class-Config.html Doc. Documentation
  Accessible without login HTML file class-ConfigExample.html Doc. Documentation
  Accessible without login HTML file class-Exception.html Doc. Documentation
  Accessible without login HTML file deprecated.html Doc. Documentation
  Accessible without login Plain text file elementlist.js Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login HTML file namespace-None.html Doc. Documentation
  Accessible without login HTML file namespace-PHP.html Doc. Documentation
  Accessible without login HTML file source-class-Config.html Doc. Documentation
  Accessible without login HTML file source-class-ConfigExample.html Doc. Documentation
  Accessible without login HTML file todo.html Doc. Documentation
  Accessible without login HTML file tree.html Doc. Documentation

  Files folder image Files  /  doc  /  resources  
File Role Description
  Accessible without login Image file collapsed.png Icon Icon image
  Accessible without login Plain text file combined.js Data Auxiliary data
  Accessible without login Image file footer.png Data Auxiliary data
  Accessible without login Image file inherit.png Icon Icon image
  Accessible without login Image file resize.png Icon Icon image
  Accessible without login Image file sort.png Icon Icon image
  Accessible without login Plain text file style.css Data Auxiliary data
  Accessible without login Image file tree-cleaner.png Icon Icon image
  Accessible without login Image file tree-hasnext.png Icon Icon image
  Accessible without login Image file tree-last.png Data Auxiliary data
  Accessible without login Image file tree-vertical.png Icon Icon image

  Files folder image Files  /  nbproject  
File Role Description
Files folder imageprivate (3 files, 1 directory)
  Accessible without login Plain text file project.properties Data Auxiliary data
  Accessible without login Plain text file project.xml Data Auxiliary data

  Files folder image Files  /  nbproject  /  private  
File Role Description
Files folder imageconfigs (1 file)
  Accessible without login Plain text file config.properties Data Auxiliary data
  Accessible without login Plain text file private.properties Data Auxiliary data
  Accessible without login Plain text file private.xml Data Auxiliary data

  Files folder image Files  /  nbproject  /  private  /  configs  
File Role Description
  Accessible without login Plain text file config.properties Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:180
This week:1
All time:8,714
This week:571Up