From a8dfd71b903b2b4fd3bceaf56999868190e31fa6 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 9 Nov 2021 11:11:31 +0800 Subject: [PATCH] up: update readme and add some new methods --- README.md | 5 +++-- src/IniEncoder.php | 8 ++++++++ src/IniParser.php | 27 ++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7654862..c5a8f2b 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/src/IniEncoder.php b/src/IniEncoder.php index c2aae08..df8ca2f 100644 --- a/src/IniEncoder.php +++ b/src/IniEncoder.php @@ -11,6 +11,14 @@ */ class IniEncoder { + /** + * @return static + */ + public static function new(): self + { + return new self(); + } + /** * @param array|Traversable $data * @param int $flags diff --git a/src/IniParser.php b/src/IniParser.php index 9562d1a..e5cca75 100644 --- a/src/IniParser.php +++ b/src/IniParser.php @@ -13,7 +13,6 @@ use function str_starts_with; use function strlen; use function strpos; -use function strstr; use function substr; use function trim; @@ -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); } @@ -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; } @@ -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 *