承接 fengsha/utils 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fengsha/utils

Composer 安装命令:

composer require fengsha/utils

包简介

这是larave工具包

README 文档

README

支持 Laravel 5.1 以上,工具包目前有 Log功能。

  • Log 对 laravel 的日志功能进行了扩展,增加了 Request LogException Log 功能

日志使用开始

Laravel 5.x:

  • 编辑项目中 composer.json 文件,增加 repostories 项
"repositories": [
        {
            "type": "git",
            "url": "git@github.com:ifengshai/php_utils.git"
        }
    ]
  • 执行 composer require fengsha/utils:dev-master 安装包

  • 增加 ServiceProvide,编辑 config/app.php

'providers' => [
    /**
     * Customer Service Providers...
     */
    Fengsha\Utils\Log\Providers\LoggerServiceProvider::class,
],
  • 增加 aliases,编辑 config/app.php
'aliases' => [
    /**
     * Customer aliases
     */
    'FsLog'      => Fengsha\Utils\Log\Facades\FsLog::class,
],
  • 增加 app_nameapp_from,编辑 config/app.php
'app_name' => 'fengsha',  // 链路追踪的时候确定是哪个服务
'app_from' => '88888888',  // 链路追踪的时候确定是哪个服务
  • 如果要替换框架原有的 Log,需要编辑 config/app.php,注释掉原有的 Log alias,并将工具命名为 Log
'aliases' => [
    // 'Log'       => Illuminate\Support\Facades\Log::class,
    /**
     * Customer aliases
     */
    'Log'      => Fengsha\Utils\Log\Facades\FsLog::class,
],
  • 发布配置
php artisan vendor:publish --provider="Fengsha\Utils\Log\Providers\LoggerServiceProvider"

Usage

Log

普通日志方法

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info
  • debug

Example:

Log::info('this is info');

特殊日志方法

  • log
  • write

Example:

Log::log('info', 'this is info');
Log::write('error', 'this is error');

基础日志变更保存路径

type 默认读取 base 配置,文件名默认为 custom.channel 名称

Log::custom('channel')->info($message, $arrContext);
// 保存路径 storage/logs/custom/custom.channel-2016-07-13.log

使用时加上自定义路径,路径定以后可以省略路径参数,路径参数请使用绝对路径

Log::custom('channel', storage_path('logs/temp/channel.log'))->info($message, $arrContext);
// 保存路径 storage/logs/temp/channel-2016-07-13.log

Log::custom('channel')->info($message, $arrContext);
// 保存路径 storage/logs/temp/channel-2016-07-13.log

路径定以后想再次变更路径

Log::custom('channel')->setPath(storage_path('logs/base/channel.log'))->info($message, $arrContext);
// 保存路径 storage/logs/base/channel-2016-07-13.log

SmokeTest

ExtensionTrait

引用

Example:

use Fengsha\Utils\SmokeTest\ExtensionTrait;

class TestController extends Controller
{
    use ExtensionTrait;

checkExtension 检测扩展

配置信息是以 key => value 的方式传递。如果key存在,则会检测该扩展是否已经被加载上。如果value存在,则会检测该扩展的版本(对版本的检测暂时只支持主版本号和次版本号的检测)。如果不想检测扩展的版本号,则可以把value设为"*",这样就可以跳过版本的检测。同时支持对php版本的检测(同样只支持主版本号和次版本号)

checkExtension方法通过$this调用

Example:

$map = [
    'php'=>'5.6.*',
    'redis'=>'2.2.*',
    'memcached'=>'*',
];
$result = [];
/**
 * 检测扩展
 * @param  array $map     配置信息
 * @param  array &$result 检测结果
 */
$this->checkExtension($map,$result);

checkExtensionVersion 测试扩展的版本号

Example:

$extension = 'redis';
$version = '2.2.*';
/**
 * 测试扩展的版本号————扩展暂时只比较主版本号和次版本号
 * @param  string $extension [扩展名]
 * @param  string $version   [版本号 *:可以是任何版本]
 * @return int               0:版本匹配,1:安装版本大于需求版本,-1:安装版本小于需求版本
 */
$this->checkExtensionVersion($extension,$version);

日志使用结束

分布式redis锁开始

如果项目没有引入过这个工具,可以在composer.json中引入,增加 repostories 项

"repositories": [
        {
            "type": "git",
            "url": "git@github.com:ifengshai/php_utils.git"
        }
    ]
  • 执行 composer require fengsha/utils:dev-master 安装包

  • 增加 ServiceProvide,编辑 config/app.php

'providers' => [
    /**
     * Customer Service Providers...
     */
     Fengsha\Utils\RedisDistributedLock\Providers\RedisDistributedLockServiceProvider::class
],
  • 增加 aliases,编辑 config/app.php
'aliases' => [
    /**
     * Customer aliases
     */
    'Lock'  => Fengsha\Utils\RedisDistributedLock\Facades\RedisDistributedLock::class
],

分布式redis锁结束

fengsha/utils 适用场景与选型建议

fengsha/utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 fengsha/utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fengsha/utils 我们能提供哪些服务?
定制开发 / 二次开发

基于 fengsha/utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-26