pantheon-systems/pantheon-edge-integrations

Helper class for content personalization.

v1.1.0 2022-06-21 20:54 UTC

This package is auto-updated.

Last update: 2024-04-22 00:52:34 UTC


README

Unsupported Packagist Release VersionBuild Status

Pantheon Edge Integrations is a PHP library which uses header data to provide a personalization object, to be used for personalizing content for each user.

Installation

Pantheon Edge Integrations can be installed via Composer from Packagist...

composer require pantheon-systems/pantheon-edge-integrations

Usage

To make use of the PHP library, ensure PHP can use the class. After which, it's possible to etiher call the library through instanced methods, or through the global methods.

use Pantheon\EI\HeaderData;

Instanced Methods

Once the class is available, headerData objects can be instantiated to make use of the API and methods can be called on it.

$headerData = new HeaderData();

getHeader($key)

Uses header key to return raw header data.

$headerData->getHeader('Audience');
// => "geo:US"

$headerData->getHeader('Interest');
// => "27"

$headerData->getHeader('Role');
// => "subscriber"

parseHeader($key)

Uses header key to return parsed header data array.

$headerData->getHeader('Audience');
// => [geo => US]

$headerData->getHeader('Interest');
// => [0 => 27]

$headerData->getHeader('Role');
// => "subscriber"

returnPersonalizationObject()

Returns an array with personalization data.

$headerData->returnPersonalizedObject();
// => [
//        Audience => [ geo => US ]
//        Interest => [ 0 => 27 ]
//        Role => subscriber
//    ]

returnVaryHeader($key)

Returns vary header array, based on header data.

Global Methods

There are also static methods defined within the class to help assist in retrieving data without having to instantiate the object yourself.

HeaderData::personalizationObject()

Gets the global personalizaition object.

Pantheon\EI\HeaderData::personalizationObject();
// => [
//        Audience => [ geo => US ]
//        Interest => [ 0 => 27 ]
//        Role => subscriber
//    ]

HeaderData::parse($key)

Parses a global header by key using a specified regex.

Pantheon\EI\HeaderData::parse('Audience');
// => [geo => US]

HeaderData::header($key)

Gets the global header data based on the given key.

Pantheon\EI\HeaderData::header('Audience');
// => geo:US

HeaderData::varyHeader()

Returns vary header array based on the global data.

Pantheon\EI\HeaderData::varyHeader('geo');

Development

PHPUnit is used to run the tests.

composer install
composer test