PHP code example of lmz / thefairlib

1. Go to this page and download the library: Download lmz/thefairlib library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lmz / thefairlib example snippets




/**
 * 阿里云CDN配置文件
 *
 * @author mingzhil
 * @mail [email protected]
 */
namespace config;

class AliYun
{
    /**
     * 只允许修改参数,其他不能改变
     */
    public $OSS = [
        'OSS_ACCESS_ID' => '**********',
        'OSS_ACCESS_KEY' => '************',
        'OSS_ENDPOINT' => 'oss-cn-beijing.aliyuncs.com',
        'OSS_TEST_BUCKET' => 'static-pub',
        'ALI_LOG' => false,
        'ALI_DISPLAY_LOG' => false,
        'ALI_LANG' => 'zh',
    ];
}


$file = new TheFairLib\Aliyun\AliOSS\Upload('file', [
    "host" => 'http://static.biyeyuan.com/',//CDN的域名、、
    "savePath" => '/tmp',//上传文件的路径
    "ossPath" => APP_NAME,//项目名称,也就是自定义阿里云目录
    "maxSize" => 2000, //单位KB
    "allowFiles" => [".gif", ".png", ".jpg", ".jpeg", ".bmp", ".css", ".js"]
]);
$data = $file->getFileInfo();
\Response\Response::Json($data);


$code = new \TheFairLib\Verify\Image();
$code->type = 'code';//类型,如login,reg,bind
$code->output(1);


$code = new \TheFairLib\Verify\Image();
$code->type = 'code';
$code->validate($_GET['code']);
echo $code->getCode();

$file = new TheFairLib\Uploader\Upload('files', [
    "savePath" => '/tmp',//上传文件的路径
    "maxSize" => 2000, //单位KB
    "allowFiles" => [".gif", ".png", ".jpg", ".jpeg", ".bmp", ".css", ".js"]
]);
$status = $file->getFileInfo();



use Yaf\Plugin_Abstract;
use Yaf\Request_Abstract;
use Yaf\Response_Abstract;
use Yaf\Registry;
use Yaf\Dispatcher;

class TplPlugin extends Plugin_Abstract
{

    /**
     * 路由结束之后触发       此时路由一定正确完成, 否则这个事件不会触发
     *
     * @param Request_Abstract $request
     * @param Response_Abstract $response
     * @return mixed|void
     */
    public function routerShutdown(Request_Abstract $request, Response_Abstract $response)
    {
        $config = Registry::get("config")->smarty->toArray();
        $config['template_dir'] = $config['template_dir'] . $request->module . '/';
        $smarty = new TheFairLib\Smarty\Adapter(null, $config);
        Dispatcher::getInstance()->setView($smarty);
    }

}

/**
 * 加载插件
 * @param \Yaf\Dispatcher $dispatcher
 */
public function _initPlugin(Yaf\Dispatcher $dispatcher)
{
    $dispatcher->registerPlugin(new TplPlugin());
}