Coder Social home page Coder Social logo

moesif-laravel's Introduction

Moesif Laravel Middlware

Source Code on GitHub

package on phppackages.org

A Middleware for PHP Laravel (> 5.1) to automatically capture incoming HTTP traffic.

How to install

Via Composer

$ composer require moesif/moesif-laravel

or add 'moesif/moesif-laravel' to your composer.json file accordingly.

How to use

Add Service Provider

// within config/app.php

'providers' => [
    //
    Moesif\Middleware\MoesifLaravelServiceProvider::class,
];

Add to Middleware

If website root is your API, add to the root level:

// within App/Http/Kernel.php

protected $middleware = [
    //
    \Moesif\Middleware\MoesifLaravel::class,
];

If API under specific route group, add to your route group:

// within App/Http/Kernel.php

protected $middlewareGroups = [
    //
    'api' => [
        //
        \Moesif\Middleware\MoesifLaravel::class,
    ],
];

To track only certain routes, use route specific middleware setup.

Publish the package config file

$ php artisan vendor:publish --provider="Moesif\Middleware\MoesifLaravelServiceProvider"

Setup config

Edit config/moesif.php file.

// within config/moesif.php

return [
    //
    'applicationId' => 'YOUR APPLICATION ID',
];

You can find your Application Id from Moesif Dashboard -> Top Right Menu -> App Setup

For other configuration options, see below.

Configuration options

You can define Moesif configuration options in the config/moesif.php file. Some of these fields are functions.

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. Moesif automatically obtains end userId via $request->user()['id'], In case you use a non standard way of injecting user into $request or want to override userId, you can do so with identifyUserId.

// within config/moesif.php

$identifyUserId = function($request, $response) {
    // $user = $request->user();
    // return $user['id'];

    return 'end_user_id';
};
return [
  //
  'identifyUserId' => $identifyUserId
];

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.

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.

// within config/moesif.php

$maskRequestHeaders = function($headers) {
    $headers['password'] = '****';
    return $headers;
};

return [
  //
  'maskRequestHeaders' => $maskRequestHeaders
];

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.

// within config/moesif.php

$maskRequestBody = function($body) {
    // remove any sensitive information.
    return $body;
};

return [
  //
  'maskRequestBody' => $maskRequestBody
];

maskResponseHeaders

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

maskResponseBody

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

debug

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

Credits for Moesif Laravel SDK

  • Parts of queuing & sending data via forked non-blocking process is based on Mixpanel's PHP client code which is open sourced under Apache License, Version 2.0.

Other integrations

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

moesif-laravel's People

Contributors

dgilling avatar xinghengwang avatar

Watchers

 avatar  avatar

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.