patbator/activitystreams 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

patbator/activitystreams

Composer 安装命令:

composer require patbator/activitystreams

包简介

Activity Streams is a simple specification used to describe social actions around the web. http://activitystrea.ms

README 文档

README

A PHP implementation of the Activity Streams 2.0

This library aims to provide AS2 vocabulary as php objets from json and to serialize them back in json. It does not aim to be a full JSON-LD implementation.

Install

With Composer

$ composer require patbator/activitystreams

Manually

Clone or download repository.

Require the provided PSR-4 autoloader to use ActivityStreams objects

require_once '[path where you cloned or downloaded this library]/autoload.php';

Usage

Let start with the first https://www.w3.org/TR/activitystreams-core/ example.

Objects to JSON

use Patbator\ActivityStreams\Model\Note;
use Patbator\ActivityStreams\Stream;

$note = new Note;
$note->content('My dog has fleas.');
$note->summary('A note');

$stream = new Stream($item);

echo $stream->render();

Will output :

{
    "@context": "https://www.w3.org/ns/activitystreams",
    "content": "My dog has fleas.",
    "summary": "A note",
    "type": "Note"
}

JSON to objects

use Patbator\ActivityStreams\Stream;

$note = Stream::fromJson('{
  "@context": "https://www.w3.org/ns/activitystreams",
  "summary": "A note",
  "type": "Note",
  "content": "My dog has fleas."
}')->getRoot();

echo $note->content();

Will output :

My dog has fleas.

See tests for more usage samples.

Extending

You could need to provide your own class for a type, for example to implement https://www.w3.org/wiki/SocialCG/ActivityPub/Authentication_Authorization.

Imagine you want an Service having a `publicKey` property.

use \Patbator\ActivityStreams\Model\Service;


class My_ActivityPub_Service extends Service 
{
  public function __construct() 
  {
    parent::__construct();
    $this->_actor_attribs[] = 'publicKey';
  }


  public function type()
  {
    return 'Service';
  }
}

You can declare it to type factory:

use Patbator\ActivityStreams\Model\Base;
use Patbator\ActivityStreams\Model\Factory;

Base::setFactory((new Factory)
                 ->mapTypeToClass('Service', 'My_ActivityPub_Service'));

After that, factory will create a new `My_ActiviyPub_Servicefor any json object with"type": "Service"instead of a\Patbator\ActivityStreams\Model\Service`.

Testing

$ composer test

License

The MIT License (MIT). Please see LICENSE.md for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固