caliper-php
caliper-php is a PHP client for Caliper that
provides an implementation of the Caliper SensorAPIā¢., (*1)
Getting Started
Pre-requisites for development
- PHP 5.4 required (PHP 5.6 recommended)
- Install Composer (for dependency management):
curl -sS https://getcomposer.org/installer | php
- Install dependencies:
php composer.phar install
-
Run tests using the Makefile: make test-caliper
, (*2)
The tests require that the caliper-common-fixtures-public
project be
installed in the same parent directory as caliper-php-public
. It is
available at:
https://github.com/IMSGlobal/caliper-common-fixtures-public.git, (*3)
Installing and Using the Library
-
Installing: There are two ways to install caliper-php. Either install by cloning the IMS
Global public version of the caliper-php GitHub repository or use Composer to
install from that same repository. The steps for each method are explained
below:, (*4)
-
Cloning caliper-php-public from GitHub, (*5)
-
Clone the repository from GitHub into your application's directory, (*6)
git clone https://github.com/IMSGlobal/caliper-php-public.git
-
Add the following to your PHP program:, (*7)
require_once '/path/to/caliper-php/lib/Caliper/Sensor.php';
-
Use Composer to install caliper-php-public from GitHub, (*8)
-
Update the composer.json
file in the root directory of your project as follows:, (*9)
-
The require
section should include the following:, (*10)
{
"require": {
"php": ">=5.4",
"ims-global/caliper-php-public": "1.0.0"
}
}
-
The repositories
section should include the following:, (*11)
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/IMSGlobal/caliper-php-public.git"
}
]
}
NOTE - These package and repository values will not work at
this time with the IMS Global repositories. The composer.json
file in caliper-php-public doesn't contain the correct entries. This
should be corrected with an update in the near future. For U-M
purposes, substitute the following values for the package
and repository, respectively:, (*12)
"umich-its-tl/caliper-php": "1.0.1"
"url": "https://github.com/tl-its-umich-edu/caliper-php-public"
This version of caliper-php-public has been modified for U-M use.
It includes a new Options::setHttpHeaders()
feature., (*13)
-
Use Composer to install the package with the command:, (*14)
composer install
Composer will create the vendor
directory to hold the package and
other related information., (*15)
-
Composer will create PHP classes to help you load Caliper (and any other
packages it has loaded) into your application. In your PHP code, use it like:, (*16)
/*
* If necessary, use set_include_path() to ensure the directory
* containing the "vendor" directory is in the PHP include path.
*/
require_once 'vendor/autoload.php'; // Composer loader for Caliper, etc.
-
After installing Caliper using one of the methods decribed above, initialize
it and send an event as follows:, (*17)
// Create Caliper sensor object
$sensor = new Sensor('your_sensor_id');
// Set sensor options
$options = (new Options())
->setApiKey('your_authentication_key_for_the_datastore')
->setDebug(true)
->setHost('http://example.org/dataStoreURI');
// Register a network transport for the sensor
$sensor->registerClient('your_http_transport_id',
new Client('your_client_id', $options));
// TODO: Define $yourCaliperEventObject
// Send a Caliper event object
$sensor->send($sensor, $yourCaliperEventObject);
Your PHP program needs to create a sensor object only once per request.
The sensor object can be reused to send multiple events within the same
request., (*18)
Running an example
A simple example program can be found in examples/SessionEventSampleApp.php
., (*19)
It will attempt to send an event to a data store listener on localhost:8000.
If you have a data store on some other host or port, you can edit the program
to use it instead. If you don't have a data store, you can run a simple
listener program included in:, (*20)
examples/tools/testListener.sh [optional_port]
That will start a simple PHP web server (on port 8000 by default) that listens for POST requests and dumps the raw contents to the terminal. If you run this in one terminal window and the example program in another terminal window, you will see the request received in the first window., (*21)
Documentation
Documentation is available at
http://www.imsglobal.org/caliper., (*22)
caliper-php-public includes as much documentation as possible in the
form of PHPDoc comments. These may appear as pop-up help in many IDEs.
phpDocumentor may be used to turn them into standalone documents., (*23)
Credits
A very special thank you to each of the developers that contributed to this project:, (*24)
- Prashant Nayak, Intellify Learning
- balachandiran.v / Yoganand-htc
- Lance E Sloan (lsloan at umich dot edu), University of Michigan
©2015 IMS Global Learning Consortium, Inc. All Rights Reserved.
Trademark Information - http://www.imsglobal.org/copyright.html, (*25)
For license information contact, info@imsglobal.org and read the LICENSE file contained in the repository., (*26)