Moesif SDK for Laravel 4.2
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

Moesif Laravel

Built For Laravel Latest Version on Packagist Total Downloads Software License

Moesif SDK for Laravel 4.2.*

Compatibility

Currently only compatible with Laravel 4.2.*

Installation

Via Composer

$ composer require jonnypickett/moesif-laravel

After updating composer, add the ServiceProvider to the providers array in config/app.php

JonnyPickett\MoesifLaravel\ServiceProvider::class,

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 config:publish jonnypickett/moesif-laravel

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

<?php

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

    'application_id' => getEnv('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) {
        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) {
        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' => getEnv('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.

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.