forked from sgoendoer/sonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SonicClientBasicExample.php
40 lines (32 loc) · 1.71 KB
/
SonicClientBasicExample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php namespace sgoendoer\Sonic\examples;
require_once(__DIR__ . '/../vendor/autoload.php');
use sgoendoer\Sonic\Sonic;
use sgoendoer\Sonic\Identity\EntityAuthData;
use sgoendoer\Sonic\Identity\SocialRecordManager;
try
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// importing SocialRecord objects to work with
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// load SocialRecords from files to instatiaze the Sonic framework
$srp = SocialRecordManager::importSocialRecord(file_get_contents(__DIR__ . '/data/SRPlatform.json'));
$platformSocialRecord = $srp['socialRecord'];
$platformAccountKeyPair = $srp['accountKeyPair'];
$platformPersonalKeyPair = $srp['personalKeyPair'];
$sra = SocialRecordManager::importSocialRecord(file_get_contents(__DIR__ . '/data/SRAlice.json'));
$userSocialRecord = $sra['socialRecord'];
$userAccountKeyPair = $sra['accountKeyPair'];
$userPersonalKeyPair = $sra['personalKeyPair'];
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// initializing Sonic SDK
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// instantiaze the Sonic framework with the platform's SocialRecord
$sonic = Sonic::initInstance(new EntityAuthData($platformSocialRecord, $platformAccountKeyPair, $platformPersonalKeyPair));
Sonic::setUserAuthData(new EntityAuthData($userSocialRecord, $userAccountKeyPair));
Sonic::setContext(Sonic::CONTEXT_USER);
}
catch (\Exception $e)
{
die($e->getMessage() . "\n\n" . $e->getTraceAsString());
}
?>