respectify/respectify-php

PHP library for the Respectify API

Maintainers

Package info

github.com/Respectify/respectify-php

pkg:composer/respectify/respectify-php

Statistics

Installs: 273

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.4.0 2026-04-23 19:04 UTC

README

PHP library for the Respectify API. Respectify aims to improve internet discussions: encourage healthy, understanding discussion in comments and replies.

Getting started

This contains the Respectify client, which is currently available only as an asychronous API using ReactPHP.

Check out src/RespectifyClientAsync.php. For info on the REST API that it wraps, have a look here.

If you are migrating from Google's Perspective API, use the dedicated Perspective compatibility sub-client:

$client->perspective()->analyzeComment([
    'comment' => ['text' => 'You clearly did not read the article.'],
    'requestedAttributes' => [
        'TOXICITY' => new stdClass(),
        'INSULT' => new stdClass(),
    ],
])->then(function ($result) {
    echo $result->attributeScores['TOXICITY']->summaryScore->value . "\n";
});

$client->run();

Developing

To be able to make changes:

$ brew install php
$ brew install composer

If you want to run unit tests:

$ composer require --dev phpunit/phpunit mockery/mockery vlucas/phpdotenv

and then to run tests:

$ vendor/bin/phpunit --bootstrap vendor/autoload.php tests

Tests are run against mocks, but there is value in running against the real API. Do do this create a tests/.venv file, with content:

USE_REAL_API=true
RESPECTIFY_EMAIL=you@example.com
RESPECTIFY_API_KEY=your-api-key-here
REAL_ARTICLE_ID=an-existing-article-id-here

using real Respectify credentials.

Docs

Docs are generated in Markdown format for Docusaurus via the phpdocumentor-markdown-customised phpdoc theme. It is MIT-licensed. Please see the readme in that folder for more information.

You'll need twig and php-documentor installed (install the dev dependencies.)

If you have a phpdoc command available (eg, set up as a Docker container):

$ alias phpdoc="docker run --rm -v \"$(pwd)\":/data phpdoc/phpdoc:3"

then you can general doc like so:

# Run phpDocumentor with --template argument pointed to markdown template
$ phpdoc --directory=src --target=docs --template="phpdocumentor-markdown-customised/themes/markdown" --title="Respectify PHP Library" -c phpdoc.xml