Skip to content

Commit

Permalink
up: update readme and add some new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 9, 2021
1 parent 82e264e commit a8dfd71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# INI

[![License](https://img.shields.io/packagist/l/phppkg/ini.svg?style=flat-square)](LICENSE)
[![Php Version](https://img.shields.io/badge/php-%3E=7.2.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/phppkg/ini)
[![License](https://img.shields.io/github/license/phppkg/ini?style=flat-square)](LICENSE)
[![Php Version](https://img.shields.io/packagist/php-v/phppkg/ini?maxAge=2592000)](https://packagist.org/packages/phppkg/ini)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/ini)](https://github.com/phppkg/ini)
[![Actions Status](https://github.com/phppkg/ini/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/ini/actions)

Expand All @@ -14,6 +14,7 @@
- enhance: supports inline array value
- enhance: supports multi inline string. use `'''` or `"""`
- enhance: supports add interceptor before collect value
- TODO: support parse ENV var. `${SHELL | bash}`

## Install

Expand Down
8 changes: 8 additions & 0 deletions src/IniEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
*/
class IniEncoder
{
/**
* @return static
*/
public static function new(): self
{
return new self();
}

/**
* @param array|Traversable $data
* @param int $flags
Expand Down
27 changes: 24 additions & 3 deletions src/IniParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use function str_starts_with;
use function strlen;
use function strpos;
use function strstr;
use function substr;
use function trim;

Expand Down Expand Up @@ -79,7 +78,7 @@ class IniParser
*
* @return static
*/
public static function new(string $source): self
public static function new(string $source = ''): self
{
return new self($source);
}
Expand All @@ -89,7 +88,7 @@ public static function new(string $source): self
*
* @param string $source
*/
public function __construct(string $source)
public function __construct(string $source = '')
{
$this->source = $source;
}
Expand Down Expand Up @@ -282,6 +281,28 @@ public function getSource(): string
return $this->source;
}

/**
* @param string $source
*
* @return IniParser
*/
public function setSource(string $source): self
{
$this->source = $source;
return $this;
}

/**
* @param callable $interceptor
*
* @return IniParser
*/
public function addInterceptor(callable $interceptor): self
{
$this->interceptors[] = $interceptor;
return $this;
}

/**
* @param callable[] $interceptors
*
Expand Down

0 comments on commit a8dfd71

Please sign in to comment.