PHP code example of fengzyz / tools

1. Go to this page and download the library: Download fengzyz/tools 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/ */

    

fengzyz / tools example snippets


    添加缓存
    你可以使用Cache 门面上的put方法在缓存中存储缓存项。当你在缓存中存储缓存项的时候,你需要指定数据被缓存的时间(分钟数):
    CacheRedis::pull($key,$name,$time)
    #add方法只会在缓存项不存在的情况下添加缓存项到缓存,如果缓存项被添加到缓存返回true,否则,返回false:
    CacheRedis::add($key,$name,$time)
    获取缓存
    $data = CacheRedis::get($key);
    
    // 获取并且添加
    $data = CacheRedis::cacheResult($key,$func,$time)

 'Illuminate\Database\Events\QueryExecuted' => [
               'Fengzyz\Listeners\QueryListener'
           ] ,



namespace App;

use App\Services\UserService;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Tymon\JWTAuth\Contracts\JWTSubject;    

class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
{
    use Authenticatable, Authorizable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email',
    ];
    protected $primaryKey = 'user_id';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password',
    ];

    /**
     * 获取唯一标识的,可以用来认证的字段名,比如 id,guid
     * @return string
     */
    public function getAuthIdentifierName()
    {
        return $this->primaryKey;
    }

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    /**
     *  获取用户信息
     * @param int $userId
     */
    public function getUser(int $userId)
    {
        return (new UserService())->getUser($userId);
    }
}


 public function test()
    {
        $fileName = time().'.png';
        $logoPath = storage_path('app/logo.png');
        $config = array(
            'ecc' => 'H',    // L-smallest, M, Q, H-best
            'size' => 12,    // 1-50
            'dest_file' => $fileName,
            'quality' => 90,
            'logo' => $logoPath,
            'logo_size' => 100,
            'logo_outline_size' => 20,
//            'logo_outline_color' => '#F0FFF0',
            'logo_radius' => 15,
            'logo_opacity' => 100,
        );
// 二维码内容
        $data = 'http://costalong.com';
// 创建二维码类
        $oPHPQRCode = new PHPQRCode();
// 设定配置
        $oPHPQRCode->setConfig($config);
// 创建二维码
        $qrcode = $oPHPQRCode->generate($data);
// 显示二维码
        echo '<img src="'.$qrcode.'?t='.time().'">';
    }

     /**
     * [合併兩張圖片]
     * @param $source1 [图片一,大图]
     * @param $source2 [图片二,小图]
     * @param null $saveName [图片合成后输出路劲]
     * @param int $alpha [透明度]
     * @param int $position [偏移九宫格位置1,2,3,4,5,6,7,8,9]
     * @param null $posX [小图偏移位置]
     * @param null $posY [小图偏移位置]
     * @return bool
     */
 ImageTools::combine($fileName,'/var/www/img.png','/var/www/orgTest.jpg',0,5,40);