定制 sgoendoer/sonic 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sgoendoer/sonic

Composer 安装命令:

composer require sgoendoer/sonic

包简介

SOcial Network InterConnect SDK

关键字:

README 文档

README

SOcial Network InterConnect

The Sonic SDK provides a complete toolset to ease the integration of the Sonic protocol into new and existing Online Social Network (OSN) platforms. It is written in PHP 5.6 and is fully compatible with PHP 7.0. The Sonic SDK can be installed via Composer or fetched directly from GitHub.

System requirements

  • PHP 5.6+ or PHP 7.0+
  • OpenSSL 1.0.0+
  • cURL 7.20.0+
  • composer

Changelog

0.5.1

0.5.0

  • Reworked resource migration
  • Reworked resource feature
  • Reworked resource link
  • Renamed resource stream to activity
  • Marked resource person deprecated
  • Added resource image
  • Improvement and fixes

0.3.0

  • Added Access Control functionality
  • Added code examples
  • Various fixes and improvements

0.2.5

  • Added feature negotiation functionality
  • Various fixes and improvements

0.2.0

  • Added migration functionality
  • Added search functionality
  • Various fixes and improvements

0.1.9

  • Added unit tests
  • Added logging support
  • Code cleanup
  • Removed unused classes/functions
  • Various fixes and improvements

0.1.0

  • Initial release

Installation

Install via composer with

$ composer require sgoendoer/sonic

or configure your composer.json like this:

"require": {
	"sgoendoer/sonic": "0.5.1"
}

and run

$ composer update

Configuration

For the configuration of the Sonic class, the sgoendoer\Sonic\Config\Configuration can be populated with the desired values. Values, which are not set explicitly will stay at their default values.

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

Configuration values

name type description default value
timezone String Timezone of the platform "Europe/Berlin"
verbose Integer Level of verbosity in the logs (0: nothing, 5: everything) 0
curlVerbose Integer Level of verbosity for curl requests (0: nothing, 1: everything, 2: also connections to third party services) 0
requestTimeout Integer Timeout for Sonic requests in seconds 10
gslsTimeout Integer Timeout for GSLS requests in seconds 4
logfile String filename to write logs to "sonic.log"
apiPath String Path to the API endpoint "/sonic/"
primaryGSLSNode String IP address of the primary GSLS node "130.149.22.220:4002"
secondaryGSLSNode String IP address of the secondary GSLS node "130.149.22.227:4002"

Initialization

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use sgoendoer\Sonic\Sonic;

use sgoendoer\Sonic\Config\Configuration;

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

try {
	// Sonic requires the \Sonic\Identity\SocialRecord of the Sonic platform for
	// initialization. Here, we import one from a String resource using
	// \Sonic\Identity\SocialRecordManager
	
	$platformSR = '{"socialRecord":{"@context": --truncated-- }';
	
	$sr = SocialRecordManager::importSocialRecord($platformSR);
	$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) {}
?>

Documentation

Code examples

More examples including explanation of the code can be found here

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

sgoendoer/sonic 适用场景与选型建议

sgoendoer/sonic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 129 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「social」 「sonic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sgoendoer/sonic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sgoendoer/sonic 我们能提供哪些服务?
定制开发 / 二次开发

基于 sgoendoer/sonic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 129
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-20