Download the PHP package rikudou/activity-pub without Composer

On this page you can find all versions of the php package rikudou/activity-pub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package activity-pub

ActivityPub for PHP

A strongly typed and developer friendly ActivityPub implementation. All Core and Extended types are implemented. Also some widely used unofficial extensions.

Table of contents

Installation

composer require rikudou/activity-pub

Objects

Naming

All object names are the same as in the ActivityPub/ActivityStreams specifications, with the sole exception of the base Object which is called BaseObject because PHP disallows having a class called Object.

Objects and activities

To construct an object, simply create it as you normally would, for example, let's construct a note:

This prints:

Validations

All property assignments are validated using various set of rules depending on the type of the property and object. There are multiple modes of validation:

For example:

When running the snippet above, you get this exception:

Uncaught Rikudou\ActivityPub\Exception\InvalidPropertyValueException: The value for property 'id' is not valid: string(123): the value must be a valid uri

Now let's do the same with changing the validation level to none:

This prints the following JSON:

If you don't want to change the validator mode for every object individually, you can also use the GlobalSettings class:

The above code prints the same JSON. Note that if you change the validator mode for an individual object, the global setting doesn't have any effect anymore, until you manually set it back to null.

The last option is to use the runInNoValidationContext function:

The same caveats as for changing the global mode exist (because all this function does is it changes the global mode, runs your function, changes it back to the original value).

Non-standard properties

If you wish to use non-standard properties, you can use the setter:

Note that unless you disable validation, custom properties are not allowed, so the above needs to run in the no-validation context:

Parsing JSON into types

While exporting ActivityPub objects to JSON is great, you'll need the exact opposite if you want to handle incoming activities!

Luckily for us, there's a TypeParser (more specifically, a class implementing the interface, DefaultTypeParser). Let's take the previous example as our input:

Creating your own types

All the ActivityPub objects can be extended by your own classes. The built-in ones use property hooks to automatically validate the values, but you can do it any other way, just make sure the properties are publicly readable.

Let's create a custom type:

Adding a property is easy:

Now, if you create your cat, you can check out the response JSON:

Now, if you want to make sure your cat always has some lives, you can mark the property as required:

You also need to specify the minimum validator mode that it's required on. If you set it to Lax, it will be required on Lax, Strict and Recommended. If you set it to Strict, it will be required on Strict and Recommended.

And now creating our cat throws this exception:

Now, let's get fancy and create our cat! And announce it to the world!

All this prints this complicated-looking ActivityPub activity which can be sent to every ActivityPub server in the whole world!

Now, if your Cat object ever becomes so popular that everything using ActivityPub sends them back and forth, you might want to register the type in the parser, otherwise it would just throw an exception saying that it doesn't know about the Cat object.

Server

In addition to the ActivityPub object, there are also various helpers for implementing ActivityPub in your server. All of them rely on the PSR abstractions, so it should be easy to use them with your favourite http client or a framework of choice.

Request signing

While not part of the ActivityPub protocol itself, you won't get far in the Fediverse without signing your request - almost no mainstream software accepts activities that are unsigned. For signing to work, each actor must be publicly accessible at the URL pointed to in its ID and have a publicKey property with the public key defined.

For this reason, this package includes two things:

  1. A non-standard publicKey property available for all actors
    • If you use the Recommended validator mode, this property is required for all actors
  2. An ActorKeyGenerator service which generates a private and public key-pair that should be stored in a database for all actors.

Example:

Now you have an actor who can send signed requests!

Now let's take a look at a hypothetical service that sends your requests:

Request validating

Of course the reverse, validating an incoming request, is also possible!

Fetching objects

Fetching remote objects can be handled using the ObjectFetcher and WebFinger services (implemented by ActivityPubObjectFetcher and DefaultWebFinger respectively).

Symfony usage

To use this library in Symfony, simply configure the PSR-7 Bridge and create the following file in config/packages/activity_pub.yaml:

If you also want to use the built-in activity sender, you need to create a service implementing Rikudou\ActivityPub\Server\Abstraction\LocalActorResolver and add the following to the above yaml:


All versions of activity-pub with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
psr/http-client Version ^1.0
ext-openssl Version *
psr/http-factory Version ^1.1
rikudou/iterables Version ^1.3
rikudou/array-merge-recursive Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rikudou/activity-pub contains the following files

Loading the files please wait ....