magicalex/write-ini-file

Write-ini-file php library for create, remove, erase, add, and update ini file

2.0.1 2019-04-24 23:14 UTC

This package is auto-updated.

Last update: 2024-03-25 09:42:22 UTC


README

Write-ini-file php library for create, remove, erase, add, and update ini file.

Build Status Coverage Status StyleCI Latest Stable Version Total Downloads License

Installation

Use composer for install magicalex/write-ini-file.

composer require magicalex/write-ini-file

Usage

<?php

require_once 'vendor/autoload.php';

use \WriteiniFile\WriteiniFile;
use \WriteiniFile\ReadiniFile;

$data = [
    'fruit' => ['orange' => '100g', 'fraise' => '10g'],
    'legume' => ['haricot' => '20g', 'oignon' => '100g'],
    'jus' => ['orange' => '1L', 'pomme' => '1,5L', 'pamplemousse' => '0,5L'],
];

// demo create ini file
$file = new WriteiniFile('file.ini');
$file
    ->create($data)
    ->add(['music' => ['rap' => true, 'rock' => false]])
    ->rm(['jus' => ['pomme' => '1,5L']])
    ->update(['fruit' => ['orange' => '200g']])
    ->write();

echo '<pre>'.file_get_contents('file.ini').'</pre>';
/* output file.ini
[fruit]
orange=200g
fraise=10g

[legume]
haricot=20g
oignon=100g

[jus]
orange=1L
pamplemousse=0,5L

[music]
rap=true
rock=false
*/

// Just read a file ini
var_dump(ReadiniFile::get('file.ini'));
/* output
array(4) {
  'fruit' => array(2) {
    'orange' => string(4) "200g"
    'fraise' => string(3) "10g"
  }
  'legume' => array(2) {
    'haricot' => string(3) "20g"
    'oignon' => string(4) "100g"
  }
  'jus' => array(2) {
    'orange' => string(2) "1L"
    'pamplemousse' => string(4) "0,5L"
  }
  'music' => array(2) {
    'rap' => string(4) "true"
    'rock' => string(5) "false"
  }
}
*/

$erase = (new WriteiniFile('file.ini'))->erase()->write();
// file.ini -> empty

Contributing

To run the unit tests:

composer install
php vendor/bin/phpunit # or use: composer run-script test

License

WriteiniFile is released under the GNU General Public License v3.0