Skip to content

Commit

Permalink
chore: update readme add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 7, 2022
1 parent 93266a9 commit 792fd3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ val_arr_two[some_key] = "some_key_value"
Decode from INI string.

```php
use PhpPkg\Ini\Ini;use Toolkit\Stdlib\Std\Collection;
use PhpPkg\Ini\Ini;
use Toolkit\Stdlib\Std\Collection;

$data = Ini::decode($ini);
vdump($data);
Expand Down Expand Up @@ -150,7 +151,31 @@ $data = Ini::decodeFile($iniFile);
Encode data to INI string.

```php
$data = [
'key0' => 'val0',
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3',
'key4' => 'val4',
'arrKey' => [
'abc',
'def',
],
];

$iniString = Ini::encode($data);
echo $iniString;
```

**Output**:

```ini
key0 = val0
key1 = val1
key2 = val2
key3 = val3
key4 = val4
arrKey = [abc, def]
```

## License
Expand Down
24 changes: 24 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,31 @@ $data = Ini::decodeFile($iniFile);
Encode data to INI string.

```php
$data = [
'key0' => 'val0',
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3',
'key4' => 'val4',
'arrKey' => [
'abc',
'def',
],
];

$iniString = Ini::encode($data);
echo $iniString;
```

**Output**:

```ini
key0 = val0
key1 = val1
key2 = val2
key3 = val3
key4 = val4
arrKey = [abc, def]
```

## License
Expand Down
3 changes: 3 additions & 0 deletions src/IniEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public function encode(array|Traversable $data, int $flags = 0): string
$defSecIni = $this->encodeSection('', $defSec) . PHP_EOL;
}

if (!$strings) {
return $defSecIni;
}
return $defSecIni . implode("\n", $strings) . PHP_EOL;
}

Expand Down
4 changes: 2 additions & 2 deletions test/IniEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testEncode_simple(): void
'key3' => 'val3',
'key4' => 'val4',
'arrKey' => [
0 => 'abc',
1 => 'def',
'abc',
'def',
],
];

Expand Down

0 comments on commit 792fd3d

Please sign in to comment.