- 优化代码

v6 v6.0.101
Chaim 4 years ago
parent 9335b3be86
commit 9d6bdb4e77

@ -1,3 +1,6 @@
## v6.0.101 / 2020-07-25
- 优化代码
## v6.0.100 / 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) [![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) [![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) [![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) [![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')) { if (!function_exists('get_ip_info')) {
/** /**

@ -21,6 +21,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception; use think\Exception;
use ZipArchive; use ZipArchive;
@ -35,12 +36,12 @@ class Files
* 删除文件 * 删除文件
* @param string $name 路径 * @param string $name 路径
* @return bool * @return bool
* @throws Exception * @throws DtaException
*/ */
public function delete(string $name): bool public function delete(string $name): bool
{ {
if (empty($name)) { if (empty($name)) {
throw new Exception('请检查需要删除文件夹的名称'); throw new DtaException('请检查需要删除文件夹的名称');
} }
if (file_exists($name)) { if (file_exists($name)) {
if (unlink($name)) { if (unlink($name)) {
@ -54,12 +55,13 @@ class Files
* 删除文件夹 * 删除文件夹
* @param string $name 路径 * @param string $name 路径
* @return bool * @return bool
* @throws DtaException
* @throws Exception * @throws Exception
*/ */
public function deletes(string $name): bool public function deletes(string $name): bool
{ {
if (empty($name)) { if (empty($name)) {
throw new Exception('请检查需要删除文件夹的名称'); throw new DtaException('请检查需要删除文件夹的名称');
} }
//先删除目录下的文件: //先删除目录下的文件:
$dh = opendir($name); $dh = opendir($name);
@ -88,12 +90,12 @@ class Files
* @param string $suffix_name 需要打包的后缀名,默认.png * @param string $suffix_name 需要打包的后缀名,默认.png
* @param string $file_name 文件名,默认全部名 * @param string $file_name 文件名,默认全部名
* @return bool * @return bool
* @throws Exception * @throws DtaException
*/ */
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{ {
if (empty($name)) { if (empty($name)) {
throw new Exception('请检查需要打包的路径名称'); throw new DtaException('请检查需要打包的路径名称');
} }
try { try {
// 获取目录下所有某个结尾的文件列表 // 获取目录下所有某个结尾的文件列表
@ -109,7 +111,7 @@ class Files
//关闭压缩包 //关闭压缩包
$zip->close(); $zip->close();
return true; return true;
} catch (\Exception $e) { } catch (\DtaException $e) {
return false; return false;
} }
} }

@ -21,6 +21,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception; use think\Exception;
/** /**
@ -34,12 +35,13 @@ class Xmls
* 数组转换为xml * 数组转换为xml
* @param array $values 数组 * @param array $values 数组
* @return string * @return string
* @throws DtaException
* @throws Exception * @throws Exception
*/ */
public function toXml(array $values) public function toXml(array $values)
{ {
if (!is_array($values) || count($values) <= 0) { if (!is_array($values) || count($values) <= 0) {
throw new Exception('数组数据异常!'); throw new DtaException('数组数据异常!');
} }
$xml = "<xml>"; $xml = "<xml>";
foreach ($values as $key => $val) { foreach ($values as $key => $val) {
@ -59,12 +61,12 @@ class Xmls
* 将XML转为array * 将XML转为array
* @param string $xml * @param string $xml
* @return mixed * @return mixed
* @throws Exception * @throws DtaException
*/ */
public function toArray(string $xml) public function toArray(string $xml)
{ {
if (!$xml) { if (!$xml) {
throw new Exception('xml数据异常'); throw new DtaException('xml数据异常');
} }
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);

Loading…
Cancel
Save