PHP code example of sgoendoer / sonic

1. Go to this page and download the library: Download sgoendoer/sonic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sgoendoer / sonic example snippets


Configuration::setTimezone('Europe/Berlin')
Configuration::setVerbose(1);



goendoer\Sonic\Sonic;

use sgoendoer\Sonic\Config\Configuration;

use sgoendoer\Sonic\Identity\EntityAuthData;
use sgoendoer\Sonic\Identity\SocialRecord;
use sgoendoer\Sonic\Identity\SocialRecordManager;

try {
	// Sonic tformSR);
	$platformSocialRecord = $sr['socialRecord'];
	$platformAccountKeyPair = $sr['accountKeyPair'];
	$platformPersonalKeyPair = $sr['personalKeyPair'];
	
	// We do the same for a user "Alice's" \Sonic\Identity\SocialRecord
	
	$aliceSR = '{"socialRecord":{"@context": --truncated -- }';
	
	$sr = SocialRecordManager::importSocialRecord($aliceSR);
	$userSocialRecord = $sr['socialRecord'];
	$userAccountKeyPair = $sr['accountKeyPair'];
	$userPersonalKeyPair = $sr['personalKeyPair'];
	
	// Before we can initialize the Sonic SDK, we need to pass a few configuration parameters.
	// Parameters we don't set explicitly will be set to default values.
	
	Configuration::setTimezone('Europe/Berlin');
	Configuration::setVerbose(1);
	
	// Now, we can initialize the Sonic SDK. The SDK's context will be set to "platform"
	// automatically
	
	$sonic = Sonic::initInstance(new EntityAuthData(
									$platformSocialRecord,
									$platformAccountKeyPair,
									$platformPersonalKeyPair));
											
	// From this point on, the Sonic SDK is fully initialized. Anyhow, the context must be
	// set to "user" in order to perform requests in the context of a user:
	
	Sonic::setUserAuthData(
		new EntityAuthData($userSocialRecord, $userAccountKeyPair));
	Sonic::setContext(Sonic::CONTEXT_USER);
	
	// Now we can perform a request to another user's profile using a GlobalID
	
	$globalID = '28B6TE8T9NUO202C5NZIUTNQSP88E70B8JAWH4FQ58OJOB8LIF';
	
	$response = (new ProfileRequestBuilder($globalID))
				->createGETProfile()
				->dispatch();
	$profile = ProfileObjectBuilder::buildFromJSON($response->getPayload());
	
	echo $profile->getJSONString() . "\n\n";
} catch (\Exception $e) {}