v5.1
Chaim 4 years ago
commit 3eb9c518da

@ -0,0 +1,2 @@
## v5.1.0 / 2020-04-13
- 测试

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,38 @@
<img align="right" width="100" src="https://cdn.oss.liguangchun.cn/04/999e9f2f06d396968eacc10ce9bc8a.png" alt="dtApp Logo"/>
<h1 align="left"><a href="https://www.dtapp.net/">ThinkPhp5.1扩展包</a></h1>
📦 ThinkPhp5.1扩展包
[![Latest Stable Version](https://poser.pugx.org/liguangchun/think-library/v/stable)](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)
[![License](https://poser.pugx.org/liguangchun/think-library/license)](https://packagist.org/packages/liguangchun/think-library)
## 依赖环境
1. PHP5.6 版本及以上
## 安装
### 开发版
```text
composer require liguangchun/think-library ^5.1-dev -vvv
```
### 稳定版
```text
composer require liguangchun/think-library ^5.1.* -vvv
```
## 更新
```text
composer update liguangchun/think-library -vvv
```
## 删除
```text
composer remove liguangchun/think-library -vvv
```

@ -0,0 +1,2 @@
@echo off
composer update -vvv --profile --prefer-dist --optimize-autoloader

@ -0,0 +1,42 @@
{
"name": "liguangchun/think-library",
"description": "ThinkPhp扩展包",
"keywords": [
"liguangchun",
"think-library",
"think",
"thinkphp",
"library"
],
"time": "2020-04-13",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Chaim",
"email": "gc@dtapp.net",
"homepage": "https://api.dtapp.net"
}
],
"homepage": "https://www.dtapp.net",
"require": {
"php": ">=5.6.0",
"topthink/framework": "5.1.*",
"liguangchun/ip": "^1.1"
},
"autoload": {
"files": [
"src/common.php"
],
"psr-4": {
"DtApp\\ThinkLibrary\\": "src"
}
},
"extra": {
"think": {
"services": [
"DtApp\\ThinkLibrary"
]
}
}
}

@ -0,0 +1,10 @@
## 创建控制器
`
php think make:controller index@Blog
`
### 创建模型
`
php think make:model Models/Ip
`

@ -0,0 +1,181 @@
<?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 Preg
* @package DtApp\ThinkLibrary
*/
class Preg
{
/**
* 验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public function isIphone($mobile)
{
if (preg_match('/^[1]([3-9])[0-9]{9}$/', $mobile)) return true;
return false;
}
/**
* 严谨验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public function isIphoneAll($mobile)
{
if (preg_match('/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/', $mobile)) return true;
return false;
}
/**
* 验证电话号码
* @access public
* @param $tel
* @return bool
*/
public function isTel($tel)
{
if (preg_match("/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/", $tel)) return true;
return false;
}
/**
* 验证身份证号15位或18位数字
* @access public
* @param int $id 身份证号码
* @return bool
*/
public function isIdCard($id)
{
if (preg_match("/^\d{15}|\d{18}$/", $id)) return true;
return false;
}
/**
* 验证是否是数字(这里小数点会认为是字符)
* @access public
* @param $digit
* @return bool
*/
public function isDigit($digit)
{
if (preg_match("/^\d*$/", $digit)) return true;
return false;
}
/**
* 验证是否是数字(可带小数点的数字)
* @access public
* @param $num
* @return bool
*/
public function isNum($num)
{
if (is_numeric($num)) return true;
return false;
}
/**
* 验证由数字、26个英文字母或者下划线组成的字符串
* @access public
* @param $str
* @return bool
*/
public function isStr($str)
{
if (preg_match("/^\w+$/", $str)) return true;
return false;
}
/**
* 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @access public
* @param $str
* @return bool
*/
public function isPassword($str)
{
if (preg_match("/^[a-zA-Z]\w{5,17}$/", $str)) return true;
return false;
}
/**
* 验证汉字
* @access public
* @param $str
* @return bool
*/
public function isChinese($str)
{
if (preg_match("/^[\u4e00-\u9fa5],{0,}$/", $str)) return true;
return false;
}
/**
* 验证Email地址
* @access public
* @param $email
* @return bool
*/
public function isEmail($email)
{
if (preg_match("/^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)) return true;
return false;
}
/**
* 验证网址URL
* @access public
* @param $url
* @return bool
*/
public function isLink($url)
{
if (preg_match("/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $url)) return true;
return false;
}
/**
* 腾讯QQ号
* @access public
* @param $qq
* @return bool
*/
public function isQq($qq)
{
if (preg_match("/^[1-9][0-9]{4,}$/", $qq)) return true;
return false;
}
/**
* 验证IP地址
* @access public
* @param $ip
* @return bool
*/
public function isIp($ip)
{
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) return true;
return false;
}
}

@ -0,0 +1,63 @@
<?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 think\App;
use think\Container;
/**
* 自定义服务基类
* Class Service
* @package DtApp\ThinkLibrary
*/
abstract class Service
{
/**
* 应用实例
* @var App
*/
protected $app;
/**
* Service constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->initialize();
}
/**
* 初始化服务
* @return $this
*/
protected function initialize()
{
return $this;
}
/**
* 静态实例对象
* @param array $args
* @return static
*/
public static function instance(...$args)
{
return Container::getInstance()->make(static::class, $args);
}
}

@ -0,0 +1,60 @@
<?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
// +----------------------------------------------------------------------
use DtApp\Ip\IpException;
use DtApp\Ip\QqWry;
if (!function_exists('get_ip_info')) {
/**
* 获取请求IP信息
* @param string $ip
* @return string
* @throws IpException
*/
function get_ip_info($ip = '')
{
if (empty($ip)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $arr[0];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
}
$qqwry = new QqWry();
return $qqwry->getLocation($ip);
}
}
if (!function_exists('get_ip')) {
/**
* 获取请求IP
* @return string
*/
function get_ip()
{
$ip = '';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $arr[0];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}

@ -0,0 +1,36 @@
<?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\Preg
* @package think\facade
* @mixin \DtApp\ThinkLibrary\Preg
* @package DtApp\ThinkLibrary\facade
* @method bool isIphone($mobile) static 验证手机号码
*/
class Preg extends Facade
{
protected static function getFacadeClass()
{
return 'DtApp\ThinkLibrary\Preg';
}
}

@ -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\service;
use DtApp\ThinkLibrary\Service;
/**
* 测试服务
* Class TestService
* @package DtApp\ThinkLibrary\service
*/
class TestService extends Service
{
public function index()
{
return 'service.test.index';
}
}

@ -0,0 +1,23 @@
<?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
// +----------------------------------------------------------------------
use DtApp\ThinkLibrary\facade\Preg;
use DtApp\ThinkLibrary\service\TestService;
require '../vendor/autoload.php';
var_dump(Preg::isIphone(13800138000));
var_dump(TestService::instance()->index());
Loading…
Cancel
Save