- 优化错误

v6
Chaim 4 years ago
parent 48e73532a2
commit d80da81679

@ -17,7 +17,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException; use think\Exception;
use ZipArchive; use ZipArchive;
/** /**
@ -32,11 +32,11 @@ class Files
* 删除文件 * 删除文件
* @param string $name 路径 * @param string $name 路径
* @return bool * @return bool
* @throws DtaException * @throws Exception
*/ */
public function delete(string $name): bool public function delete(string $name): bool
{ {
if (empty($name)) throw new DtaException('请检查需要删除文件夹的名称'); if (empty($name)) throw new Exception('请检查需要删除文件夹的名称');
if (file_exists($name)) if (unlink($name)) return true; if (file_exists($name)) if (unlink($name)) return true;
return false; return false;
} }
@ -45,11 +45,11 @@ class Files
* 删除文件夹 * 删除文件夹
* @param string $name 路径 * @param string $name 路径
* @return bool * @return bool
* @throws DtaException * @throws Exception
*/ */
public function deletes(string $name): bool public function deletes(string $name): bool
{ {
if (empty($name)) throw new DtaException('请检查需要删除文件夹的名称'); if (empty($name)) throw new Exception('请检查需要删除文件夹的名称');
//先删除目录下的文件: //先删除目录下的文件:
$dh = opendir($name); $dh = opendir($name);
while ($file = readdir($dh)) { while ($file = readdir($dh)) {
@ -71,11 +71,11 @@ 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 DtaException * @throws Exception
*/ */
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)) throw new DtaException('请检查需要打包的路径名称'); if (empty($name)) throw new Exception('请检查需要打包的路径名称');
try { try {
// 获取目录下所有某个结尾的文件列表 // 获取目录下所有某个结尾的文件列表
$list = glob($name . "{$file_name}.{$suffix_name}"); $list = glob($name . "{$file_name}.{$suffix_name}");

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\helper; namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException; use think\Exception;
/** /**
* XML管理类 * XML管理类
@ -30,11 +30,11 @@ class Xmls
* 数组转换为xml * 数组转换为xml
* @param array $values 数组 * @param array $values 数组
* @return string * @return string
* @throws DtaException * @throws Exception
*/ */
public function toXml(array $values) public function toXml(array $values)
{ {
if (!is_array($values) || count($values) <= 0) throw new DtaException('数组数据异常!'); if (!is_array($values) || count($values) <= 0) throw new Exception('数组数据异常!');
$xml = "<xml>"; $xml = "<xml>";
foreach ($values as $key => $val) { foreach ($values as $key => $val) {
if (is_array($val)) { if (is_array($val)) {
@ -53,11 +53,11 @@ class Xmls
* 将XML转为array * 将XML转为array
* @param string $xml * @param string $xml
* @return mixed * @return mixed
* @throws DtaException * @throws Exception
*/ */
public function toArray(string $xml) public function toArray(string $xml)
{ {
if (!$xml) throw new DtaException('xml数据异常'); if (!$xml) throw new Exception('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