forked from landrok/activitypub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e00cf22
Showing
4 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016-2017 landrok at github.com/landrok | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
ActivityPub | ||
=========== | ||
|
||
ActivityPub is an implementation of ActivityPub layers in PHP. | ||
|
||
It provides two layers: | ||
|
||
- A __client to server protocol__, or "Social API" | ||
This protocol permits a client to act on behalf of a user. | ||
- A __server to server protocol__, or "Federation Protocol" | ||
This protocol is used to distribute activities between actors on different servers, tying them into the same social graph. | ||
|
||
As the two layers are implemented, it aims to be an ActivityPub conformant Federated Server | ||
|
||
All normalized types are implemented too. If you need to create a new | ||
one, just extend existing types. | ||
|
||
Table of contents | ||
================= | ||
|
||
- [Install](#install) | ||
- [Requirements](#requirements) | ||
- [Features](#features) | ||
- [Core Types](#core-types) | ||
- [Extended Types](#extended-types) | ||
- [Usage](#usage) | ||
|
||
________________________________________________________________________ | ||
|
||
Requirements | ||
------------ | ||
|
||
- Supports PHP7+ | ||
|
||
________________________________________________________________________ | ||
|
||
Install | ||
------- | ||
|
||
```sh | ||
composer require landrok/activitypub | ||
``` | ||
|
||
________________________________________________________________________ | ||
|
||
ActivityPub Core Types | ||
---------------------- | ||
|
||
All core types are provided: | ||
|
||
```php | ||
use ActivityPub\Type\Core\Activity; | ||
use ActivityPub\Type\Core\Collection; | ||
use ActivityPub\Type\Core\CollectionPage; | ||
use ActivityPub\Type\Core\IntransitiveActivity; | ||
use ActivityPub\Type\Core\Link; | ||
use ActivityPub\Type\Core\ObjectType; | ||
use ActivityPub\Type\Core\OrderedCollection; | ||
use ActivityPub\Type\Core\OrderedCollectionPage; | ||
``` | ||
________________________________________________________________________ | ||
|
||
ActivityPub Extended Types | ||
-------------------------- | ||
|
||
All extended types are provided: | ||
|
||
### Actor types | ||
|
||
```php | ||
use ActivityPub\Type\Extended\Actor\Application; | ||
use ActivityPub\Type\Extended\Actor\Group; | ||
use ActivityPub\Type\Extended\Actor\Organization; | ||
use ActivityPub\Type\Extended\Actor\Person; | ||
use ActivityPub\Type\Extended\Actor\Service; | ||
``` | ||
|
||
### Activity types | ||
|
||
```php | ||
use ActivityPub\Type\Extended\Activity\Accept; | ||
use ActivityPub\Type\Extended\Activity\Add; | ||
use ActivityPub\Type\Extended\Activity\Announce; | ||
use ActivityPub\Type\Extended\Activity\Arrive; | ||
use ActivityPub\Type\Extended\Activity\Block; | ||
use ActivityPub\Type\Extended\Activity\Create; | ||
use ActivityPub\Type\Extended\Activity\Delete; | ||
use ActivityPub\Type\Extended\Activity\Dislike; | ||
use ActivityPub\Type\Extended\Activity\Flag; | ||
use ActivityPub\Type\Extended\Activity\Follow; | ||
use ActivityPub\Type\Extended\Activity\Ignore; | ||
use ActivityPub\Type\Extended\Activity\Invite; | ||
use ActivityPub\Type\Extended\Activity\Join; | ||
use ActivityPub\Type\Extended\Activity\Leave; | ||
use ActivityPub\Type\Extended\Activity\Like; | ||
use ActivityPub\Type\Extended\Activity\Listen; | ||
use ActivityPub\Type\Extended\Activity\Move; | ||
use ActivityPub\Type\Extended\Activity\Offer; | ||
use ActivityPub\Type\Extended\Activity\Question; | ||
use ActivityPub\Type\Extended\Activity\Read; | ||
use ActivityPub\Type\Extended\Activity\Reject; | ||
use ActivityPub\Type\Extended\Activity\Remove; | ||
use ActivityPub\Type\Extended\Activity\TentativeAccept; | ||
use ActivityPub\Type\Extended\Activity\TentativeReject; | ||
use ActivityPub\Type\Extended\Activity\Travel; | ||
use ActivityPub\Type\Extended\Activity\Undo; | ||
use ActivityPub\Type\Extended\Activity\Update; | ||
use ActivityPub\Type\Extended\Activity\View; | ||
``` | ||
|
||
### Object types | ||
|
||
```php | ||
use ActivityPub\Type\Extended\Object\Article; | ||
use ActivityPub\Type\Extended\Object\Audio; | ||
use ActivityPub\Type\Extended\Object\Document; | ||
use ActivityPub\Type\Extended\Object\Event; | ||
use ActivityPub\Type\Extended\Object\Image; | ||
use ActivityPub\Type\Extended\Object\Mention; | ||
use ActivityPub\Type\Extended\Object\Note; | ||
use ActivityPub\Type\Extended\Object\Page; | ||
use ActivityPub\Type\Extended\Object\Place; | ||
use ActivityPub\Type\Extended\Object\Profile; | ||
use ActivityPub\Type\Extended\Object\Relationship; | ||
use ActivityPub\Type\Extended\Object\Tombstone; | ||
use ActivityPub\Type\Extended\Object\Video; | ||
``` | ||
|
||
________________________________________________________________________ | ||
|
||
Usage | ||
----- | ||
|
||
### Hydrate a core type | ||
|
||
```php | ||
use ActivityPub\Type\Extended\Object\Note; | ||
|
||
$note = new Note(); | ||
$note->id = 'https://example.com/notes/1'; | ||
``` | ||
|
||
|
||
### Extend a core type | ||
|
||
```php | ||
use ActivityPub\Type\Extended\Object\Note; | ||
|
||
class MyNote extends Note | ||
{ | ||
// Override basic type | ||
protected $type = 'CustomNote'; | ||
|
||
// Custom property | ||
protected $myProperty; | ||
} | ||
|
||
$note = new MyNote(); | ||
$note->id = 'https://example.com/custom-notes/1'; | ||
$note->myProperty = 'Custom Value'; | ||
``` | ||
|
||
### Add custom validators for objects attributes | ||
|
||
There is 2 possible cases: | ||
|
||
1. Usage of custom attributes | ||
2. Override ActivityPub attribute validation | ||
|
||
Regarding to previous example with a custom attribute `$myProperty`, if | ||
you try to set this property, it would be done without any check on | ||
values you're providing. | ||
|
||
You can easily cope with that implementing a custom validator using | ||
`ValidatorHelper`. | ||
|
||
```php | ||
use ActivityPub\Type\Helper\ValidatorInterface; | ||
use ActivityPub\Type\Helper\ValidatorHelper; | ||
|
||
// Create a custom validator that implements ValidatorInterface | ||
class MyPropertyValidator implements ValidatorInterface | ||
{ | ||
// A public validate() method is mandatory | ||
public function validate($value) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
// Attach this validator to a property | ||
ValidatorHelper::addFilter('myProperty', MyPropertyValidator::class); | ||
|
||
// Now all values are checked | ||
$note->myProperty = 'Custom Value'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "landrok/activitypub", | ||
"type": "library", | ||
"version": "0.1.0-dev", | ||
"description": "A PHP implementation of ActivityPub protocol based upon the ActivityStreams 2.0 data format.", | ||
"keywords": ["ActivityPub", "ActivityStreams", "federation"], | ||
"homepage": "https://github.com/landrok/activitypub", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ActivityPub\\": "src/ActivityPub/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"ActivityPubTest\\": "tests/ActivityPub/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="ActivityPub Test Suite"> | ||
<directory>./tests/ActivityPub</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |