提交 9d6bdb4e 编写于 作者: 李光春's avatar 李光春

- 优化代码

上级 9335b3be
## v6.0.101 / 2020-07-25
- 优化代码
## v6.0.100 / 2020-07-25
- 优化淘宝客
......
......@@ -8,7 +8,11 @@
[![Latest Unstable Version](https://poser.pugx.org/liguangchun/think-library/v/unstable)](https://packagist.org/packages/liguangchun/think-library)
[![Total Downloads](https://poser.pugx.org/liguangchun/think-library/downloads)](https://packagist.org/packages/liguangchun/think-library)
[![License](https://poser.pugx.org/liguangchun/think-library/license)](https://packagist.org/packages/liguangchun/think-library)
[![PHP Version](https://img.shields.io/badge/php-%3E%3D7.1-8892BF.svg)](http://www.php.net/)
[![Code Health](https://hn.devcloud.huaweicloud.com/codecheck/v1/codecheck/task/codehealth.svg?taskId=1567f5ea332546c3b45f4024cf50f10b)](https://hn.devcloud.huaweicloud.com/codecheck/project/c7ff3e2d65674858bd363cb43ee6c35e/codecheck/task/1567f5ea332546c3b45f4024cf50f10b/detail)
[![Build Status](https://travis-ci.org/GC0202/ThinkLibrary.svg?branch=6.0)](https://travis-ci.org/GC0202/ThinkLibrary)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/quality-score.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
[![Code Coverage](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/coverage.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
## 依赖环境
......
......@@ -26,7 +26,7 @@ use think\db\exception\DbException;
/**
* 定义当前版本
*/
const VERSION = '6.0.100';
const VERSION = '6.0.101';
if (!function_exists('get_ip_info')) {
/**
......
......@@ -21,6 +21,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception;
use ZipArchive;
......@@ -35,12 +36,12 @@ class Files
* 删除文件
* @param string $name 路径
* @return bool
* @throws Exception
* @throws DtaException
*/
public function delete(string $name): bool
{
if (empty($name)) {
throw new Exception('请检查需要删除文件夹的名称');
throw new DtaException('请检查需要删除文件夹的名称');
}
if (file_exists($name)) {
if (unlink($name)) {
......@@ -54,12 +55,13 @@ class Files
* 删除文件夹
* @param string $name 路径
* @return bool
* @throws DtaException
* @throws Exception
*/
public function deletes(string $name): bool
{
if (empty($name)) {
throw new Exception('请检查需要删除文件夹的名称');
throw new DtaException('请检查需要删除文件夹的名称');
}
//先删除目录下的文件:
$dh = opendir($name);
......@@ -88,12 +90,12 @@ class Files
* @param string $suffix_name 需要打包的后缀名,默认.png
* @param string $file_name 文件名,默认全部名
* @return bool
* @throws Exception
* @throws DtaException
*/
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{
if (empty($name)) {
throw new Exception('请检查需要打包的路径名称');
throw new DtaException('请检查需要打包的路径名称');
}
try {
// 获取目录下所有某个结尾的文件列表
......@@ -109,7 +111,7 @@ class Files
//关闭压缩包
$zip->close();
return true;
} catch (\Exception $e) {
} catch (\DtaException $e) {
return false;
}
}
......
......@@ -21,6 +21,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception;
/**
......@@ -34,12 +35,13 @@ class Xmls
* 数组转换为xml
* @param array $values 数组
* @return string
* @throws DtaException
* @throws Exception
*/
public function toXml(array $values)
{
if (!is_array($values) || count($values) <= 0) {
throw new Exception('数组数据异常!');
throw new DtaException('数组数据异常!');
}
$xml = "<xml>";
foreach ($values as $key => $val) {
......@@ -59,12 +61,12 @@ class Xmls
* 将XML转为array
* @param string $xml
* @return mixed
* @throws Exception
* @throws DtaException
*/
public function toArray(string $xml)
{
if (!$xml) {
throw new Exception('xml数据异常!');
throw new DtaException('xml数据异常!');
}
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册