<?php // The purpose of this script is to drive the interface for interface testing. // It is light weight and doesn't require special SDKs or libs to be installed, // just a php interpreter and a SPLYT data collector to point it at. define('SSF_SERVER', 'http://localhost'); require_once '../include/Splyt.php'; require_once '../include/Splyt_Custom.php'; // ### INIT ### $splyt = Splyt::init('rsb-dataexample-test', 'user', 'device'); // ### BEGIN TXN ### // Lots of defaults $splyt->Custom->beginTransaction('begin'); // Timeout combinations $splyt->Custom->beginTransaction('begin', $timeoutMode = Splyt::TIMEOUT_MODE_TRANSACTION); $splyt->Custom->beginTransaction('begin', null, 30); $splyt->Custom->beginTransaction('begin', $timeoutMode = Splyt::TIMEOUT_MODE_TRANSACTION, 30); $splyt->Custom->beginTransaction('begin', $timeoutMode = Splyt::TIMEOUT_MODE_ANY, 30); // Full $splyt->Custom->beginTransaction('begin', $timeoutMode = Splyt::TIMEOUT_MODE_ANY, 30, array('property' => 5), 'mytxnid'); // ### UPDATE TXN ### $splyt->Custom->updateTransaction('update', 50, array('property' => 6)); $splyt->Custom->updateTransaction('update', 50, null, 'mytxnid'); $splyt->Custom->updateTransaction('update', 50, array('property' => 6), 'mytxnid'); // ### END TXN ### $splyt->Custom->endTransaction('end'); $splyt->Custom->endTransaction('end', Splyt::TXN_ERROR); $splyt->Custom->endTransaction('end', null, array('property' => 7)); $splyt->Custom->endTransaction('end', null, null, 'mytxnid'); $splyt->Custom->endTransaction('end', Splyt::TXN_ERROR, array('property' => 7), 'mytxnid'); // ### UPDATE USER STATE ###
if (!isset($_REQUEST['userid'])) { return json_encode(array('status' => 'invalidargs')); } // include fakememcache here, as a convenience require_once dirname(__FILE__) . '/fakememcache.php'; // If XML_Serializer is not already in the include_path, dynamically add the // folder that is bundled with this sample that includes a copy of XML_Serializer // (along with its own dependencies). if (!in_include_path('XML/Serializer.php')) { set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pear'); } // initialize split here, since all services will include this code require_once dirname(__FILE__) . '/Splyt/Splyt.php'; // We must always initialize Splyt before use with either a user id, a device id, or both. In // the case of BubblePop, we use only a user id $splyt = Splyt::init('rsb-bubblepopphp-test', $_REQUEST['userid']); /** * Determines whether a file is found in the PHP include path. * * @param $file The file to find. * * Newer PHP versions could use stream_resolve_include_path(); this function * is provided in case we're running on an older version. */ function in_include_path($file) { $paths = explode(PATH_SEPARATOR, get_include_path()); $found = false; foreach ($paths as $p) { $fullname = $p . DIRECTORY_SEPARATOR . $file; if (is_file($fullname)) {
/** * Retrieves the values for all tuning variables for a given user/device and caches them using the * Splyt_ext interface provided by the application. */ public function cacheVariables() { if (!isset(self::$sExt)) { error_log("cacheVariables() may not be used unless a Splyt_ext class is available. See documentation for more details"); return Error::InvalidArgs("cacheVariables() may not be used unless a Splyt_ext class is available. See documentation for more details"); } isset($this->userId) && self::$sExt->clear(self::$cachePfx . 'USER' . $this->userId); isset($this->deviceId) && self::$sExt->clear(self::$cachePfx . 'DEVICE' . $this->deviceId); // if we have any batched telem, be sure to send it before the call to cache variables self::$ssfClientBatch->sendBatch(); // Don't use batching because the response is important if (!isset(self::$ssfClientCVars)) { self::$ssfClientCVars = new SSFClient(array('SSF_CUSTOMER_ID' => $this->customerId, 'SSF_BATCHMODE' => false)); } // Determine the proper method for retrieving variables based upon the configuration provided $method = null; if (!isset($this->userId) && !isset($this->deviceId)) { error_log("No userId or deviceId provided. Please check your call to Splyt.init()"); return Error::InvalidArgs("No userId or deviceId provided. Please check your call to Splyt.init()"); } else { if (!isset($this->userId) || !isset($this->deviceId)) { $method = 'tuner_getAllValues'; if (!isset($this->userId)) { $args = array(SSFSendTimeToken, SSFEventTimeToken, $this->deviceId, 'DEVICE'); } else { $args = array(SSFSendTimeToken, SSFEventTimeToken, $this->userId, 'USER'); } } else { $method = 'tuner_getAllValuesAllTypes'; $args = array(SSFSendTimeToken, SSFEventTimeToken, $this->userId, $this->deviceId); } } // make the call - note: this will result in a network transaction $ret = call_user_func_array(array(self::$ssfClientCVars, $method), $args); if ($ret->isError()) { error_log($ret->getErrorString()); return $ret; } // parse the response and cache using the Splyt_ext interface if (isset($ret['type'])) { if ($ret['type'] == 'USER') { self::$sExt->store(self::$cachePfx . 'USER' . $this->userId, $ret['value']); } if ($ret['type'] == 'DEVICE') { self::$sExt->store(self::$cachePfx . 'DEVICE' . $this->deviceId, $ret['value']); } } else { if (isset($ret['USER'])) { self::$sExt->store(self::$cachePfx . 'USER' . $this->userId, $ret['USER']['data']['value']); } if (isset($ret['DEVICE'])) { self::$sExt->store(self::$cachePfx . 'DEVICE' . $this->deviceId, $ret['DEVICE']['data']['value']); } } return Error::Success(); }