- 数字、网址、文件门面

v6
Chaim 4 years ago
parent 920fb935f0
commit c93ec6cf8f

@ -24,7 +24,10 @@
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"liguangchun/ip": "^1.1",
"ext-gd": "*"
"ext-gd": "*",
"ext-libxml": "*",
"ext-json": "*",
"ext-simplexml": "*"
},
"autoload": {
"files": [
@ -38,7 +41,10 @@
"think": {
"services": [
"DtApp\\ThinkLibrary"
]
],
"config": {
"dtapp": "src/config.php"
}
}
}
}

@ -19,6 +19,7 @@ namespace DtApp\ThinkLibrary;
/**
* 日期管理类
* Class Date
* @mixin Date
* @package DtApp\ThinkLibrary
*/
class Date

@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
/**
* 文件管理类
* Class Files
* @mixin Files
* @package DtApp\ThinkLibrary
*/
class Files
{
/**
* 删除文件
* @param string $name
* @return bool
*/
public function delete(string $name)
{
if (file_exists($name)) if (unlink($name)) return true;
return false;
}
}

@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
/**
* 数字管理类
* Class Ints
* @mixin Ints
* @package DtApp\ThinkLibrary
*/
class Ints
{
/**
* 判断一个数是不是偶数
* @param int $num
* @return bool
*/
public function isEvenNumbers(int $num)
{
if ($num % 2 == 0) return true;
return false;
}
/**
* 判断一个数是不是奇数
* @param int $num
* @return bool
*/
public function isOddNumbers(int $num)
{
if ($num % 2 == 0) return false;
return true;
}
}

@ -19,6 +19,7 @@ namespace DtApp\ThinkLibrary;
/**
* 验证管理类
* Class Preg
* @mixin Preg
* @package DtApp\ThinkLibrary
*/
class Preg

@ -19,6 +19,7 @@ namespace DtApp\ThinkLibrary;
/**
* 时间管理类
* Class Time
* @mixin Time
* @package DtApp\ThinkLibrary
*/
class Time

@ -19,6 +19,7 @@ namespace DtApp\ThinkLibrary;
/**
* 唯一ID管理类
* Class UnIqId
* @mixin UnIqId
* @package DtApp\ThinkLibrary
*/
class UnIqId

@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
/**
* 网址管理类
* Class Urls
* @mixin Urls
* @package DtApp\ThinkLibrary
*/
class Urls
{
/**
* 编码
* @param string $url
* @return string
*/
public function lenCode(string $url)
{
if (empty($url)) return false;
return urlencode($url);
}
/**
* 解码
* @param string $url
* @return string
*/
public function deCode(string $url)
{
if (empty($url)) return false;
return urldecode($url);
}
/**
* 格式化参数格式化成url参数
* @param array $data
* @return string
*/
public function toParams(array $data)
{
$buff = "";
foreach ($data as $k => $v) if ($k != "sign" && $v !== "" && !is_array($v)) $buff .= $k . "=" . $v . "&";
$buff = trim($buff, "&");
return $buff;
}
}

@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use DtApp\ThinkLibrary\exception\DtAppException;
/**
* XML管理类
* Class Xmls
* @mixin Xmls
* @package DtApp\ThinkLibrary
*/
class Xmls
{
/**
* 数组转换为xml
* @param array $values 数组
* @return string
* @throws DtAppException
*/
public function toXml(array $values)
{
if (!is_array($values) || count($values) <= 0) throw new DtAppException('数组数据异常!');
$xml = "<xml>";
foreach ($values as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . toXml($val) . "</" . $key . ">";
} else if (is_numeric($val)) {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
} else {
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
}
}
$xml .= "</xml>";
return $xml;
}
/**
* 将XML转为array
* @param string $xml
* @return mixed
* @throws DtAppException
*/
public function toArray(string $xml)
{
if (!$xml) throw new DtAppException('xml数据异常');
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
}
}

@ -0,0 +1,17 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
return [];

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use Exception;
/**
* 错误管理
* Class DtAppException
* @package DtApp\ThinkLibrary\exception
*/
class DtAppException extends Exception
{
public function errorMessage()
{
return $this->getMessage();
}
}

@ -24,10 +24,14 @@ use think\Facade;
* @see \DtApp\ThinkLibrary\Date
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Date
* @package DtApp\ThinkLibrary\facade
*/
class Date extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Date';

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\facade;
use think\Facade;
/**
* 文件门面
* Class Preg
* @see \DtApp\ThinkLibrary\Files
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Files
*
* @method \DtApp\ThinkLibrary\Files delete(string $name) bool 编码
*/
class Files extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Files';
}
}

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\facade;
use think\Facade;
/**
* 数字门面
* Class Preg
* @see \DtApp\ThinkLibrary\Ints
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Ints
*
* @method \DtApp\ThinkLibrary\Ints isEvenNumbers(int $num) bool 判断一个数是不是偶数
* @method \DtApp\ThinkLibrary\Ints isOddNumbers(int $num) bool 判断一个数是不是奇数
*/
class Ints extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Ints';
}
}

@ -24,7 +24,7 @@ use think\facade;
* @see \DtApp\ThinkLibrary\Preg
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Preg
* @package DtApp\ThinkLibrary\facade
*
* @method \DtApp\ThinkLibrary\Preg isIphone($mobile) bool 验证手机号码
* @method \DtApp\ThinkLibrary\Preg isIphoneAll($mobile) bool 严谨验证手机号码
* @method \DtApp\ThinkLibrary\Preg isTel($tel) bool 验证电话号码
@ -41,6 +41,11 @@ use think\facade;
*/
class Preg extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Preg';

@ -24,7 +24,7 @@ use think\Facade;
* @see \DtApp\ThinkLibrary\Time
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Time
* @package DtApp\ThinkLibrary\facade
*
* @method \DtApp\ThinkLibrary\Time getData(string $format = "Y-m-d H:i:s") false|string 当前时间
* @method \DtApp\ThinkLibrary\Time getTime() false|string 当前时间戳
* @method \DtApp\ThinkLibrary\Time getUDate() false|string 当前时间戳
@ -36,6 +36,11 @@ use think\Facade;
*/
class Time extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Time';

@ -24,13 +24,18 @@ use think\Facade;
* @see \DtApp\ThinkLibrary\UnIqId
* @package think\facade
* @mixin \DtApp\ThinkLibrary\UnIqId
* @package DtApp\ThinkLibrary\facade
*
* @method \DtApp\ThinkLibrary\UnIqId random($size = 10, $type = 1, $prefix = '') static 获取随机字符串编码
* @method \DtApp\ThinkLibrary\UnIqId date($size = 16, $prefix = '') static 唯一日期编码
* @method \DtApp\ThinkLibrary\UnIqId number($size = 12, $prefix = '') static 唯一数字编码
*/
class UnIqId extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\UnIqId';

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\facade;
use think\Facade;
/**
* 网址门面
* Class Preg
* @see \DtApp\ThinkLibrary\Urls
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Urls
*
* @method \DtApp\ThinkLibrary\Urls lenCode(string $url) static 编码
* @method \DtApp\ThinkLibrary\Urls deCode(string $url) static 解码
* @method \DtApp\ThinkLibrary\Urls toParams(array $data) static 格式化参数格式化成url参数
*/
class Urls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Urls';
}
}

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\facade;
use think\Facade;
/**
* XML门面
* Class Preg
* @see \DtApp\ThinkLibrary\Xmls
* @mixin \DtApp\ThinkLibrary\Xmls
* @package DtApp\ThinkLibrary\facade
* @method \DtApp\ThinkLibrary\Xmls toXml(array $values) string 数组转换为xml
* @method \DtApp\ThinkLibrary\Xmls toArray(string $xml) string 将XML转为array
*/
class Xmls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Xmls';
}
}
Loading…
Cancel
Save