Skip to content

Commit

Permalink
update some methods and remove YamlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 10, 2021
1 parent b4eea54 commit a10d650
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 147 deletions.
34 changes: 4 additions & 30 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Toolkit\FsUtil\Exception\IOException;
use Toolkit\FsUtil\Parser\IniParser;
use Toolkit\FsUtil\Parser\JsonParser;
use Toolkit\FsUtil\Parser\YamlParser;
use Toolkit\FsUtil\Traits\FileOperateTrait;
use Toolkit\FsUtil\Traits\FileSnippetReadTrait;
use function dirname;
Expand Down Expand Up @@ -83,11 +82,6 @@ public static function parse(string $src, string $format = self::FORMAT_PHP): ar
{
$src = trim($src);
switch ($format) {
case self::FORMAT_YML:
case self::FORMAT_YAML:
$array = self::parseYaml($src);
break;

case self::FORMAT_JSON:
$array = self::parseJson($src);
break;
Expand All @@ -97,9 +91,10 @@ public static function parse(string $src, string $format = self::FORMAT_PHP): ar
break;

case self::FORMAT_PHP:
default:
$array = self::loadPhp($src);
$array = self::loadPhpFile($src);
break;
default:
throw new InvalidArgumentException('unsupported format ' . $format);
}

return $array;
Expand All @@ -114,7 +109,7 @@ public static function parse(string $src, string $format = self::FORMAT_PHP): ar
* @return array
* @throws FileNotFoundException
*/
public static function loadPhp(string $file, bool $throwError = true): array
public static function loadPhpFile(string $file, bool $throwError = true): array
{
$ary = [];

Expand Down Expand Up @@ -172,27 +167,6 @@ public static function loadIni(string $fileOrContents): array
return IniParser::parse($fileOrContents);
}

/**
* @param string $fileOrContents 要解析的 yml 文件名 或 字符串内容。
*
* @return array
*/
public static function parseYaml(string $fileOrContents): array
{
return YamlParser::parse($fileOrContents);
}

/**
* @param string $fileOrContents 要解析的 yml 文件名 或 字符串内容。
*
* @return array
* @deprecated please use parseYaml()
*/
public static function loadYaml(string $fileOrContents): array
{
return YamlParser::parse($fileOrContents);
}

/**********************************************************************************
* php function wrapper, add error handle
*********************************************************************************/
Expand Down
116 changes: 0 additions & 116 deletions src/Parser/YamlParser.php

This file was deleted.

7 changes: 6 additions & 1 deletion src/Traits/FileOperateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use function pathinfo;
use function preg_match;
use function stat;
use function str_contains;
use function strrchr;
use function strstr;
use function trim;
Expand All @@ -48,7 +49,11 @@ trait FileOperateTrait
*/
public static function getName(string $file, bool $clearExt = false): string
{
$filename = basename(trim($file));
if (!str_contains($file, '.')) {
return basename($file);
}

$filename = basename($file);

return $clearExt ? strstr($filename, '.', true) : $filename;
}
Expand Down

0 comments on commit a10d650

Please sign in to comment.