承接 studio308/moesif-laravel 相关项目开发

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

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

studio308/moesif-laravel

Composer 安装命令:

composer require studio308/moesif-laravel

包简介

Moesif SDK for Laravel 8.*

README 文档

README

Built For Laravel Latest Version on Packagist Total Downloads Software License

Moesif SDK for Laravel 8.*

Compatibility

Currently only compatible with Laravel 8.*

Installation

Via Composer

$ composer require studio308/moesif-laravel

Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Configuration

You will need to provide your Moesif Application ID in order to get this working.

You can find your Application ID from the Moesif Dashboard -> Top Right Menu -> Installation

If you don't need to change any other config values, you can get away with just setting the appropriate env variable. The necessary env variable for the Application ID is:

MOESIF_APPLICATION_ID

The other env variable that you can set is:

MOESIF_DEBUG

Some sensible defaults are set for you in the config file, but if you need to modify it, you can modify it to fit your needs after publishing it with the command below.

php artisan vendor:publish

(DO NOT PUT YOUR APPLICATION ID IN THE CONFIG FILE. USE THE ENV VARIABLE.)

Usage

Add the moesif middleware to the api middleware group in your Http/Kernel

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            ...
        ],

        'api' => [
            ...
            'moesif',
            ...
        ],
    ];

Configuration Documentation

Below is an example config/moesif.php configuration file.

<?php

return array(
    
    /*
    |--------------------------------------------------------------------------
    | Moesif Application ID
    |--------------------------------------------------------------------------
    |
    | This is the Moesif application id.
    |
    */

    'applicationId' => env('MOESIF_APPLICATION_ID'),

    /*
    |--------------------------------------------------------------------------
    | Skip
    |--------------------------------------------------------------------------
    |
    | Return true if the event is to be skipped.
    |
    */

    'skip' => function ($request, $response) {
        $host = explode('.', $request->server('HTTP_HOST'));
        return $host[0] != 'api';
    },

    /*
    |--------------------------------------------------------------------------
    | Mask Request Headers
    |--------------------------------------------------------------------------
    |
    | Add or remove request headers.
    |
    */

    'maskRequestHeaders' => function ($headers) {
        if (isset($headers['authorization'])) {
            $headers['authorization'] = str_repeat('*', 18);
        }
        return $headers;
    },

    /*
    |--------------------------------------------------------------------------
    | Mask Request Body
    |--------------------------------------------------------------------------
    |
    | Remove any fields from body that you don't want sent to Moesif.
    |
    */

    'maskRequestBody' => function ($body) {
        if (isset($body['password'])) {
            $body['password'] = str_repeat('*', 18);
        }
        return $body;
    },

    /*
    |--------------------------------------------------------------------------
    | Mask Response Headers
    |--------------------------------------------------------------------------
    |
    | Add or remove response headers.
    |
    */

    'maskResponseHeaders' => function ($headers) {
        return $headers;
    },

    /*
    |--------------------------------------------------------------------------
    | Mask Response Body
    |--------------------------------------------------------------------------
    |
    | Remove any fields from body that you don't want sent to Moesif.
    |
    */

    'maskResponseBody' => function ($body) {
        if (isset($body['token'])) {
            $body['token'] = str_repeat('*', 18);
        }
        return $body;
    },

    /*
    |--------------------------------------------------------------------------
    | Identify User ID
    |--------------------------------------------------------------------------
    |
    | Identify the user.
    |
    */

    'identifyUserId' => function ($request, $response) {
        return null;
    },

    /*
    |--------------------------------------------------------------------------
    | Identify Session ID
    |--------------------------------------------------------------------------
    |
    | Identify the session.
    |
    */

    'identifySessionId' => function ($request, $response) {
        if ($request->hasSession()) {
            return $request->session()->getId();
        } else {
            return null;
        }
    },

    /*
    |--------------------------------------------------------------------------
    | Meta Data
    |--------------------------------------------------------------------------
    |
    | Add any extra data to be sent to Moesif.
    |
    */

    'getMetaData' => function ($request, $response) {
        return [];
    },

    /*
    |--------------------------------------------------------------------------
    | Tags
    |--------------------------------------------------------------------------
    |
    | Add any tags to be sent to Moesif.
    |
    */

    'addTags' => function ($request, $response) {
        return '';
    },

    /*
    |--------------------------------------------------------------------------
    | API Version
    |--------------------------------------------------------------------------
    |
    | Identify the API Version.
    |
    */

    'apiVersion' => function ($request, $response) {
        return null;
    },

    /*
    |--------------------------------------------------------------------------
    | Debug
    |--------------------------------------------------------------------------
    |
    | Set to true to see debug information.
    |
    */

    'debug' => env('MOESIF_DEBUG', false),
    
);

Documentation for the various config values is below.

applicationId

Type: String Required, a string that identifies your application.

identifyUserId

Type: ($request, $response) => String Optional, a function that takes a $request and $response and return a string for userId.

identifyCompany

Type: ($request, $response) => String Optional, a function that takes a $request and $response and return a string for companyId.

identifySessionId

Type: ($request, $response) => String Optional, a function that takes a $request and $response and return a string for sessionId. Moesif automatically sessionizes by processing at your data, but you can override this via identifySessionId if you're not happy with the results.

getMetadata

Type: ($request, $response) => Associative Array Optional, a function that takes a $request and $response and returns $metdata which is an associative array representation of JSON.

apiVersion

Type: String Optional, a string to specifiy an API Version such as 1.0.1, allowing easier filters.

maskRequestHeaders

Type: $headers => $headers Optional, a function that takes a $headers, which is an associative array, and returns an associative array with your sensitive headers removed/masked.

maskRequestBody

Type: $body => $body Optional, a function that takes a $body, which is an associative array representation of JSON, and returns an associative array with any information removed.

maskResponseHeaders

Type: $headers => $headers Optional, same as above, but for Responses.

maskResponseBody

Type: $body => $body Optional, same as above, but for Responses.

skip

Type: ($request, $response) => String Optional, a function that takes a $request and $response and returns true if this API call should be not be sent to Moesif.

debug

Type: Boolean Optional, If true, will print debug messages using Illuminate\Support\Facades\Log

Credits for Moesif Laravel SDK

Additional Tips:

  • The forked (i.e. non-blocking way) of sending data is using exec() with a cURL command. The Php exec() command can be successful but the cURL itself may have 401 errors. So after integration, if you don't see events and data show up in your Moesif Dash. Please turn on debug option, then the cURL command itself will be logged. You can execute that cURL command and see what the issues are. The most common thing to check is if the Application ID is set correctly.

Other integrations

To view more more documentation on integration options, please visit the Integration Options Documentation.

studio308/moesif-laravel 适用场景与选型建议

studio308/moesif-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.98k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Moesif」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 studio308/moesif-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-03