Skip to content

Commit abee6dd

Browse files
committed
some update for file-parse lib
1 parent 8b26550 commit abee6dd

File tree

8 files changed

+56
-56
lines changed

8 files changed

+56
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parse ini,json,yml file.
55
## install
66

77
```bash
8-
composer require mylib/file-parse
8+
composer require toolkit/file-parse
99
```
1010

1111
## license

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "mylib/file-parse",
2+
"name": "toolkit/file-parse",
33
"type": "library",
44
"description": "some file parse tool library of the php",
55
"keywords": ["library","tool","php"],
6-
"homepage": "https://github.com/php-mylib/file-parse",
6+
"homepage": "https://github.com/php-toolkit/file-parse",
77
"license": "MIT",
88
"authors": [
99
{
@@ -14,11 +14,11 @@
1414
],
1515
"require": {
1616
"php": ">=7.0.0",
17-
"mylib/str-utils": "~1.0"
17+
"toolkit/str-utils": "~1.0"
1818
},
1919
"autoload": {
2020
"psr-4": {
21-
"MyLib\\FileParse\\" : "src/"
21+
"Toolkit\\File\\Parse\\" : "src/"
2222
}
2323
},
2424
"suggest": {

src/BaseParser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 上午11:43
77
*/
88

9-
namespace MyLib\FileParse;
9+
namespace Toolkit\File\Parse;
1010

1111
/**
1212
* Class BaseParser
13-
* @package MyLib\FileParse
13+
* @package Toolkit\File\Parse
1414
*/
1515
abstract class BaseParser
1616
{
@@ -42,7 +42,7 @@ abstract protected static function doParse(
4242
*/
4343
public static function parse($string, $enhancement = false, callable $pathHandler = null, $fileDir = ''): array
4444
{
45-
if (is_file($string)) {
45+
if (\is_file($string)) {
4646
return self::parseFile($string, $enhancement, $pathHandler, $fileDir);
4747
}
4848

@@ -59,12 +59,12 @@ public static function parse($string, $enhancement = false, callable $pathHandle
5959
*/
6060
public static function parseFile($file, $enhancement = false, callable $pathHandler = null, $fileDir = ''): array
6161
{
62-
if (!is_file($file)) {
62+
if (!\is_file($file)) {
6363
throw new \InvalidArgumentException("Target file [$file] not exists");
6464
}
6565

6666
$fileDir = $fileDir ?: \dirname($file);
67-
$data = file_get_contents($file);
67+
$data = \file_get_contents($file);
6868

6969
return static::doParse($data, $enhancement, $pathHandler, $fileDir);
7070
}

src/IniParser.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 上午11:41
77
*/
88

9-
namespace MyLib\FileParse;
9+
namespace Toolkit\File\Parse;
1010

1111
/**
1212
* Class IniParser
13-
* @package MyLib\FileParse
13+
* @package Toolkit\File\Parse
1414
*/
1515
class IniParser extends BaseParser
1616
{
@@ -53,14 +53,14 @@ protected static function doParse($string, $enhancement = false, callable $pathH
5353
}
5454

5555
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
56-
if ($fileDir && !file_exists($extendFile) && $extendFile[0] !== '/') {
57-
$extendFile = $fileDir . '/' . trim($extendFile, './');
56+
if ($fileDir && !\file_exists($extendFile) && $extendFile[0] !== '/') {
57+
$extendFile = $fileDir . '/' . \trim($extendFile, './');
5858
}
5959

6060
// $importFile is file
61-
if (is_file($extendFile)) {
62-
$data = file_get_contents($extendFile);
63-
$array = array_merge(parse_ini_string(trim($data), true), $array);
61+
if (\is_file($extendFile)) {
62+
$data = \file_get_contents($extendFile);
63+
$array = \array_merge(parse_ini_string(trim($data), true), $array);
6464
} else {
6565
throw new \UnexpectedValueException("needed extended file [$extendFile] don't exists!");
6666
}
@@ -71,23 +71,23 @@ protected static function doParse($string, $enhancement = false, callable $pathH
7171
continue;
7272
}
7373

74-
if (0 === strpos($item, self::IMPORT_KEY . '#')) {
75-
$importFile = trim(substr($item, 7));
74+
if (0 === \strpos($item, self::IMPORT_KEY . '#')) {
75+
$importFile = trim(\substr($item, 7));
7676

7777
// if needed custom handle $importFile path. e.g: Maybe it uses custom alias path
7878
if ($pathHandler && \is_callable($pathHandler)) {
7979
$importFile = $pathHandler($importFile);
8080
}
8181

8282
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
83-
if ($fileDir && !file_exists($importFile) && $importFile[0] !== '/') {
83+
if ($fileDir && !\file_exists($importFile) && $importFile[0] !== '/') {
8484
$importFile = $fileDir . '/' . trim($importFile, './');
8585
}
8686

8787
// $importFile is file
88-
if (is_file($importFile)) {
89-
$data = file_get_contents($importFile);
90-
$array[$key] = parse_ini_string(trim($data), true);
88+
if (\is_file($importFile)) {
89+
$data = \file_get_contents($importFile);
90+
$array[$key] = \parse_ini_string(trim($data), true);
9191
} else {
9292
throw new \UnexpectedValueException("needed imported file [$importFile] don't exists!");
9393
}

src/JsonParser.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* Time: 上午11:41
77
*/
88

9-
namespace MyLib\FileParse;
9+
namespace Toolkit\File\Parse;
1010

11-
use MyLib\StrUtil\JsonHelper;
11+
use Toolkit\StrUtil\JsonHelper;
1212

1313
/**
1414
* Class JsonParser
15-
* @package MyLib\FileParse
15+
* @package Toolkit\File\Parse
1616
*/
1717
class JsonParser extends BaseParser
1818
{
@@ -55,14 +55,14 @@ protected static function doParse($string, $enhancement = false, callable $pathH
5555
}
5656

5757
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
58-
if ($fileDir && !file_exists($extendFile) && $extendFile[0] !== '/') {
58+
if ($fileDir && !\file_exists($extendFile) && $extendFile[0] !== '/') {
5959
$extendFile = $fileDir . '/' . trim($extendFile, './');
6060
}
6161

6262
// $importFile is file
63-
if (is_file($extendFile)) {
64-
$data = file_get_contents($extendFile);
65-
$array = array_merge(JsonHelper::parse($data), $array);
63+
if (\is_file($extendFile)) {
64+
$data = \file_get_contents($extendFile);
65+
$array = \array_merge(JsonHelper::parse($data), $array);
6666
} else {
6767
throw new \UnexpectedValueException("needed extended file [$extendFile] don't exists!");
6868
}
@@ -73,22 +73,22 @@ protected static function doParse($string, $enhancement = false, callable $pathH
7373
continue;
7474
}
7575

76-
if (0 === strpos($item, self::IMPORT_KEY . '#')) {
77-
$importFile = trim(substr($item, 6));
76+
if (0 === \strpos($item, self::IMPORT_KEY . '#')) {
77+
$importFile = \trim(\substr($item, 6));
7878

7979
// if needed custom handle $importFile path. e.g: Maybe it uses custom alias path
8080
if ($pathHandler && \is_callable($pathHandler)) {
8181
$importFile = $pathHandler($importFile);
8282
}
8383

8484
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
85-
if ($fileDir && !file_exists($importFile) && $importFile[0] !== '/') {
85+
if ($fileDir && !\file_exists($importFile) && $importFile[0] !== '/') {
8686
$importFile = $fileDir . '/' . trim($importFile, './');
8787
}
8888

8989
// $importFile is file
90-
if (is_file($importFile)) {
91-
$data = file_get_contents($importFile);
90+
if (\is_file($importFile)) {
91+
$data = \file_get_contents($importFile);
9292
$array[$key] = JsonHelper::parse($data);
9393
} else {
9494
throw new \UnexpectedValueException("needed imported file [$importFile] don't exists!");

src/YmlParser.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* Time: 上午11:41
77
*/
88

9-
namespace MyLib\FileParse;
9+
namespace Toolkit\File\Parse;
1010

1111
use Symfony\Component\Yaml\Parser;
1212

1313
/**
1414
* Class YmlParser
15-
* @package MyLib\FileParse
15+
* @package Toolkit\File\Parse
1616
*/
1717
class YmlParser extends BaseParser
1818
{
@@ -36,7 +36,7 @@ protected static function doParse($string, $enhancement = false, callable $pathH
3636
throw new \InvalidArgumentException('param type error! must is string.');
3737
}
3838

39-
if (!class_exists(Parser::class)) {
39+
if (!\class_exists(Parser::class)) {
4040
throw new \UnexpectedValueException('yml format parser Class ' . Parser::class . " don't exists! please install package 'symfony/yaml'.");
4141
}
4242

@@ -60,14 +60,14 @@ protected static function doParse($string, $enhancement = false, callable $pathH
6060
}
6161

6262
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
63-
if ($fileDir && !file_exists($extendFile) && $extendFile[0] !== '/') {
63+
if ($fileDir && !\file_exists($extendFile) && $extendFile[0] !== '/') {
6464
$extendFile = $fileDir . '/' . trim($extendFile, './');
6565
}
6666

6767
// $importFile is file
68-
if (is_file($extendFile)) {
69-
$data = file_get_contents($extendFile);
70-
$array = array_merge($parser->parse(trim($data)), $array);
68+
if (\is_file($extendFile)) {
69+
$data = \file_get_contents($extendFile);
70+
$array = \array_merge($parser->parse(trim($data)), $array);
7171
} else {
7272
throw new \UnexpectedValueException("needed extended file $extendFile don't exists!");
7373
}
@@ -78,22 +78,22 @@ protected static function doParse($string, $enhancement = false, callable $pathH
7878
continue;
7979
}
8080

81-
if (0 === strpos($item, self::IMPORT_KEY . '#')) {
82-
$importFile = trim(substr($item, 6));
81+
if (0 === \strpos($item, self::IMPORT_KEY . '#')) {
82+
$importFile = \trim(\substr($item, 6));
8383

8484
// if needed custom handle $importFile path. e.g: Maybe it uses custom alias path
8585
if ($pathHandler && \is_callable($pathHandler)) {
8686
$importFile = $pathHandler($importFile);
8787
}
8888

8989
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile
90-
if ($fileDir && !file_exists($importFile) && $importFile[0] !== '/') {
90+
if ($fileDir && !\file_exists($importFile) && $importFile[0] !== '/') {
9191
$importFile = $fileDir . '/' . trim($importFile, './');
9292
}
9393

9494
// $importFile is file
95-
if (is_file($importFile)) {
96-
$data = file_get_contents($importFile);
95+
if (\is_file($importFile)) {
96+
$data = \file_get_contents($importFile);
9797
$array[$key] = $parser->parse(trim($data));
9898
} else {
9999
throw new \UnexpectedValueException("needed imported file $importFile don't exists!");

test/IniParserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* Time: 20:25
77
*/
88

9-
namespace MyLib\FileParse\Test;
9+
namespace Toolkit\File\Parse\Test;
1010

11-
use MyLib\FileParse\IniParser;
11+
use Toolkit\File\Parse\IniParser;
1212
use PHPUnit\Framework\TestCase;
1313

1414
/**
1515
* Class IniParserTest
16-
* @package MyLib\FileParse\Test
16+
* @package Toolkit\File\Parse\Test
1717
*/
1818
class IniParserTest extends TestCase
1919
{

test/boot.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
spl_autoload_register(function ($class) {
1111
$file = null;
1212

13-
if (0 === strpos($class,'MyLib\FileParse\Example\\')) {
14-
$path = str_replace('\\', '/', substr($class, strlen('MyLib\FileParse\Example\\')));
13+
if (0 === strpos($class,'Toolkit\File\Parse\Example\\')) {
14+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\File\Parse\Example\\')));
1515
$file = dirname(__DIR__) . "/example/{$path}.php";
16-
} elseif (0 === strpos($class,'MyLib\FileParse\Test\\')) {
17-
$path = str_replace('\\', '/', substr($class, strlen('MyLib\FileParse\Test\\')));
16+
} elseif (0 === strpos($class,'Toolkit\File\Parse\Test\\')) {
17+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\File\Parse\Test\\')));
1818
$file = __DIR__ . "/{$path}.php";
19-
} elseif (0 === strpos($class,'MyLib\FileParse\\')) {
20-
$path = str_replace('\\', '/', substr($class, strlen('MyLib\FileParse\\')));
19+
} elseif (0 === strpos($class,'Toolkit\File\Parse\\')) {
20+
$path = str_replace('\\', '/', substr($class, strlen('Toolkit\File\Parse\\')));
2121
$file = dirname(__DIR__) . "/src/{$path}.php";
2222
}
2323

0 commit comments

Comments
 (0)