https://github.com/compolomus/iniobject
https://github.com/compolomus/iniobject
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/compolomus/iniobject
- Owner: Compolomus
- License: mit
- Created: 2020-03-17T22:13:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-04T04:41:16.000Z (about 6 years ago)
- Last Synced: 2025-01-19T18:51:25.824Z (over 1 year ago)
- Language: PHP
- Size: 38.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Compolomus IniObject
[](https://packagist.org/packages/compolomus/IniObject)
[](https://scrutinizer-ci.com/g/Compolomus/IniObject/build-status/master)
[](https://scrutinizer-ci.com/g/Compolomus/IniObject/?branch=master)
[](https://scrutinizer-ci.com/g/Compolomus/IniObject/?branch=master)
[](https://codeclimate.com/github/Compolomus/IniObject)
[](https://packagist.org/packages/compolomus/IniObject)
# Install:
composer require compolomus/IniObject
# Usage:
```php
use Compolomus\IniObject\IniObject;
require __DIR__ . '/vendor/autoload.php';
$json = '{"test":{"param1":1,"param2":2},"test2":{"param3":3,"param4":4}}';
$array = json_decode($json, true); // convert to array
$object = new IniObject(
/*
If file exists, a load file, else set name to file save
*/
'test.ini', // null default
/*
Array params to preload values
*/
$array,
/*
Config params or default config (override protected property)
*/
[
'strict' => false,
'overwrite' => true,
]
);
/*
[test]
param1 = 1
param2 = 2
[test2]
param3 = 3
param4 = 4
*/
echo $object; // ini file data
/*
Get section params
*/
$params = $object->getSection('test')->toArray();
echo '
' . print_r($params, true) . '
';
/*
Array
(
[param1] => 1
[param2] => 2
)
*/
/*
Get param by name
*/
$param = $object->getSection('test')->getParam('param1'); // 1
```
**More features see in tests**