Code Monkey home page Code Monkey logo

library's Introduction

常用工具库

重构 TinkPHP 中的 Library

让任何框架都可以用 Library 的类

安装

php composer.phar require --prefer-dist guanguans/library

使用

Db

<?php
require_once '../../src/db/extend/functions.php';

use guanguans\library\db\Driver;

$User = M('User');
// 查询
$User->where(['user_name'=>'琯琯'])->select();

更多......

Env

<?php
use guanguans\library\Env;

// env 文件路径
$envFile = 'xxx/.env';
$Env = new Env($envFile);

// 获取配置 APP_NAME
$Env->get('APP_NAME');
// 设置配置 APP_TEST
$Env->set('APP_TEST', 'this is a test.');

UploadFile

html

<form action="UploadFileTest.php" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label>单文件上传</label>
        <input type="file" name="upload">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

php

<?php
use guanguans\library\UploadFile;

$upload = new UploadFile();

$UploadFile->savePath      = './upload/';    // 上传根目录
$UploadFile->saveRule      = 'uniqid/';      // 上传文件的文件名保存规则
$UploadFile->autoSub       = true;           // 上传子目录开启
$UploadFile->subType       = 'date';         // 上传子目录命名规则
$UploadFile->allowExts     = ['jpg', 'png']; // 允许类型

if ($UploadFile->upload()) {
    $UploadFile->getUploadFileInfo();
} else {
    $UploadFile->getErrorMsg();
}

Upload

html

<form action="UploadTest.php" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label>单文件上传</label>
        <input type="file" name="upload">
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

php

<?php
use guanguans\library\upload\Upload;

$config = [
	'rootPath' => 'uploads',
	'savePath' => 'images',
	'saveName' => array('uniqid',''),
	'exts'     => array('jpg', 'png'),
	'autoSub'  => true,
	'subName'  => array('date','Ymd'),
];

$Upload = new Upload($config);
$info = $Upload->upload();

if ($info) {
	$info;
} else {
    $upload->getError();
}

Verify

生成验证码

<?php
use guanguans\library\verify\Verify;

$config =    array(
	'length'   =>  4,       // 验证码位数
	'useNoise' =>  false,   // 关闭验证码杂点
	'fontttf'  =>  '5.ttf', // 字体
);

$Verify = new Verify($config);
$Verify->entry();

检查验证码

<?php
use guanguans\library\verify\Verify;

$Verify = new Verify();
$Verify->check($_POST['VerifyCode']);

CodeSwitch

<?php
use guanguans\library\CodeSwitch;

// 目录遍历
CodeSwitch::searchdir('./test')
// 编码转换
CodeSwitch::DetectAndSwitch('./test')

Crypt

<?php
use guanguans\library\crypt\Crypt;

// Base64 Crypt Des Think Xxtea
$Crypt = new Crypt('Des');

// 加密 guanguans
$encrypt = $Crypt->encrypt('guanguans', '琯琯')
// 解密 guanguans
$Crypt->decrypt($encrypt, '琯琯');

Curl

<?php
use guanguans\library\Curl;

$Curl = new Curl();

// 发送 get 请求
$Curl->get('http://baidu.com');

Date

<?php
use guanguans\library\Date;

$Date = new Date();

// 日期分析
$Date->parse('2017-07-23');
// 计算日期差
$Date->dateDiff('2017-07-23');
// 人性化的计算日期差
$Date->timeDiff('2017-07-23');
// 判断日期 所属 干支 生肖 星座
$Date->magicInfo('2017-07-23');

Dir

<?php
use guanguans\library\Dir;

// 要操作的目录
$dir = './'
$Dir = new Dir($dir);

// 取得目录下面的文件信息
$Dir->listFile()

// 删除目录(包括下面的文件)
$Dir->delDir()

// 删除目录下面的所有文件
$Dir->del()

// 复制目录
$Dir->copyDir()

Hash

<?php
use guanguans\library\hash\Hash;

// 加密
Hash::make('guanguans');

// 检查
Hash::check('guanguans', $encrypt);

Http

<?php
use guanguans\library\Http;

$Http = new Http();

// 采集远程文件       远程文件名         本地保存文件名
$Http->curlDownload('./HttpTest.php', './test.php');

// 使用 fsockopen 通过 HTTP 协议直接访问(采集)远程文件
$Http->fsockopenDownload($url, $config);

/**
 * 下载文件
 * $filename 下载文件名
 * $showname 下载显示的文件名
 * $content 下载的内容
 * $expire 下载内容浏览器缓存时间
 */
$Http->fsockopenDownload($filename, $showname, $content, $$expire);

// 显示HTTP Header 信息
$Http->getHeaderInfo('./HttpTest.php');

Image

<?php
use guanguans\library\image\Image;
use guanguans\library\image\driver\GIF;

$Image = new Image(1);

// 打开要操作的图片
$Image->open('./xxx.png');
// 将图片裁剪为400x400并保存为corp.jpg
$Image->thumb(150, 150)->save('./thumb.jpg');

更多......

IpLocation

<?php
use guanguans\library\ipLocation\IpLocation;

// 实例化类 参数表示IP地址库文件
$IpLocation = new IpLocation('QQwry-gbk.dat');

header("Content-type: text/html; charset=gbk");
// 获取某个IP地址所在的位置
$IpLocation->getlocation('61.135.169.125');

PHPZip

<?php
use guanguans\library\PHPZip;

$PHPZip = new PHPZip();

// 遍历指定文件夹
$PHPZip->visitFile('../tests');
// 压缩并直接下载
$PHPZip->ZipAndDownload('../tests');
// 压缩到服务器
$PHPZip->Zip('../tests', 'tests.zip');
// 解压文件
$PHPZip->unZip('./tests.zip', '../PHPZip');
// 获取被压缩文件的信息
$PHPZip->GetZipInnerFilesInfo('./tests.zip');
// 获取压缩文件的注释
$PHPZip->GetZipComment('./tests.zip');

PinYin

<?php
use guanguans\library\PinYin;

$PinYin = new PinYin();

$PinYin->getAllPY('PHP 是最好的语言');
$PinYin->getFirstPY('PHP 是最好的语言');

Storage

<?php
use guanguans\library\storage\Storage;

Storage::connect('file');
Storage::put('test.text','testtesttesttesttest','F');
Storage::unlink('test.text','F');

String

<?php
use guanguans\library\String;

$String = new String();

$String->uuid();
$String->randString();

Tree

use guanguans\library\Tree;

$data     = [
    ['id'=>1, 'parent_id'=>0, 'name'=>'Java', 'url'=>'url1'],
    ['id'=>2, 'parent_id'=>0, 'name'=>'PHP', 'url'=>'url2'],
    ['id'=>3, 'parent_id'=>0, 'name'=>'python', 'url'=>'url3'],
    ['id'=>4, 'parent_id'=>2, 'name'=>'ThinkPHP', 'url'=>'url4'],
    ['id'=>5, 'parent_id'=>2, 'name'=>'Laravel', 'url'=>'url5'],
    ['id'=>6, 'parent_id'=>2, 'name'=>'Yii2', 'url'=>'url6'],
    ['id'=>7, 'parent_id'=>4, 'name'=>'ThinkPHP 是一个 PHP 框架', 'url'=>'url7'],
    ['id'=>8, 'parent_id'=>4, 'name'=>'ThinkPHP 中集成 guanguans/library', 'url'=>'url8'],
    ['id'=>9, 'parent_id'=>5, 'name'=>'Laravel 是一个 PHP 框架', 'url'=>'url9']
];

$Tree       = new Tree();
$Tree->icon = ['&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ '];
$Tree->nbsp = '&nbsp;&nbsp;&nbsp;';

foreach ($data as $key => $value) {
    $data[$key]['post_name'] = '<a href="' .$value['url']. '">'.$value['name'].'</a>';
    $data[$key]['parentid'] = $value['parent_id'];
}

$Tree->init($data);
$str  = "<tr>
            <td>\$id</td>
            <td>\$spacer\$post_name</td>
            <td>\$name</td>
            <td>url</td>
        </tr>";

// 数据数据
$Tree->get_tree(0, $str);
// 树形数组
$Tree->get_tree_array(0, $str);

License

MIT

library's People

Contributors

guanguans avatar

Stargazers

 avatar  avatar

Watchers

 avatar

library's Issues

Weekly Digest (19 July, 2020 - 26 July, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (12 July, 2020 - 19 July, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (28 June, 2020 - 5 July, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (25 April, 2020 - 2 May, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (5 July, 2020 - 12 July, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (2 May, 2020 - 9 May, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (6 April, 2020 - 13 April, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (26 July, 2020 - 2 August, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (19 April, 2020 - 26 April, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Weekly Digest (2 August, 2020 - 9 August, 2020)

Here's the Weekly Digest for guanguans/library:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository guanguans/library to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.